Quicksort won't work when there are multiple copies of the same integer [JAVA]
So when I generate a random group of ten integers, the sort won't work usually.  It will only work if there are no integers repeated in the group.  I think my problem has something to do with recursion but I'm not sure where.	
Here is the main partition method

                public static int partition(int[]A, int lo, int hi)
	        {
		        int low=lo;
		        int high=hi;
		        int pivindex=(low + high) / 2;
		        System.out.println("Index is "+pivindex+ " PIVOT VALUE IS " +A[pivindex]);
		if (A.length<=2)
		{
			return 0;
		}
		else
		{
			int pivot=A[pivindex];
			int i=low;
			int j=high;
			while (j>i)
			{
				if (pivot!=A[(low+high)/2])
				{
					pivot=A[pivindex];
				}
				
				while ((A[i]<pivot)&&(j>i))
				{
					i++;
					System.out.println("I is "+i+ " VALUE IS " +A[i]);
				}
				while ((A[j]>pivot)&&(j>i))
				{
					j--;
					System.out.println("J is "+j+ " VALUE IS " +A[j]);
				}
				if (i!=j)
				{
					swap(A,i,j);
					System.out.println("SWAP");
					print(A);
				}
			}
			//System.out.println("Now partition from 0 to "+i);
			//partition(A,lo,j);
			//partition(A,i,hi);
			
		}
		return pivindex;
		
	}
	

And the actual method where recursion is used.


	public static void kwiksort (int[]A, int p, int q)
	{
		if (p<q)
		{
			int B = partition(A,p,q);
			kwiksort(A,p,B-1);
			kwiksort(A,B+1,q);
			
		}
	}
Quicksort won't work when there are multiple copies of the same integer [JAVA]
===

So when I generate a random group of ten integers, the sort won't work usually.  It will only work if there are no integers repeated in the group.  I think my problem has something to do with recursion but I'm not sure where.	
Here is the main partition method

                public static int partition(int[]A, int lo, int hi)
	        {
		        int low=lo;
		        int high=hi;
		        int pivindex=(low + high) / 2;
		        System.out.println("Index is "+pivindex+ " PIVOT VALUE IS " +A[pivindex]);
		if (A.length<=2)
		{
			return 0;
		}
		else
		{
			int pivot=A[pivindex];
			int i=low;
			int j=high;
			while (j>i)
			{
				if (pivot!=A[(low+high)/2])
				{
					pivot=A[pivindex];
				}
				
				while ((A[i]<pivot)&&(j>i))
				{
					i++;
					System.out.println("I is "+i+ " VALUE IS " +A[i]);
				}
				while ((A[j]>pivot)&&(j>i))
				{
					j--;
					System.out.println("J is "+j+ " VALUE IS " +A[j]);
				}
				if (i!=j)
				{
					swap(A,i,j);
					System.out.println("SWAP");
					print(A);
				}
			}
			//System.out.println("Now partition from 0 to "+i);
			//partition(A,lo,j);
			//partition(A,i,hi);
			
		}
		return pivindex;
		
	}
	

And the actual method where recursion is used.


	public static void kwiksort (int[]A, int p, int q)
	{
		if (p<q)
		{
			int B = partition(A,p,q);
			kwiksort(A,p,B-1);
			kwiksort(A,B+1,q);
			
		}
	}