I changed my program a little. The new problem is that the execution doesn't stop!
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package inplacesort;
import java.util.*;
/**
*
* @author ASUS
*/
public class InplaceSort
{
static Scanner console = new Scanner(System.in);
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Vector <Integer> intList = new Vector <Integer> ();
//getting the numbers from the user
char ans = 'y';
while (ans == 'Y' || ans == 'y')
{
System.out.print("Enter a Number: ");
intList.addElement(console.nextInt());
System.out.print("Do You Want to Continue?(Y/N)");
ans = console.next().charAt(0);
}
System.out.println(intList);
for (int i = 1; i < intList.size(); i++)
{
//if (intList.elementAt(i) < intList.elementAt(i-1))
//{
int j = i - 1;
while (j >= 0 && intList.elementAt(i) < intList.elementAt(j))
{
j--;
}
if (j == -1)
{
j = 0;
}
for (int k = intList.size() - 1; k >= j; k--)
{
intList.insertElementAt(intList.elementAt(k),k + 1);
}
intList.insertElementAt(intList.elementAt(i+1),j);
intList.removeElementAt(i+1);
//}
}
System.out.print(intList);
}
}