/* ============================================================================
 * Copyright (c) 2015 Imagic Bildverarbeitung AG, CH-8152 Glattbrugg.
 * All rights reserved.
 *
 * http://www.imagic.ch/
 * ============================================================================
 */
package algorithm;

import java.util.Scanner;

/**
 *
 * @version $Revision$
 * @version $Date$
 * @author $Author$
 * @owner Sandro Mario Zbinden
 */
public class QuicksortInPlace {
    public static class Solution {

		public static void quicksort(int[] ar, int low, int high) {
			if (low < high) {
				int pivotIndex = partition(ar, low, high);
				quicksort(ar, low, pivotIndex -1);
				quicksort(ar, pivotIndex +1, high);
			}
		}
        public static int partition(int[] ar, int low, int high) {
        	int pivotValue = ar[high];
        	int i = low;
        	for (int j = low; j < high; j++) {
        		if (ar[j] <= pivotValue) {
        			swap(ar, i, j);
        			i = i +1;
        		}
        	}
        	swap(ar, i, high);
        	printArrayLn(ar);
        	return i;
        }

        private static void swap(int[] ar, int i1, int i2) {
        	int tempValue = ar[i1];
        	ar[i1] = ar[i2];
        	ar[i2] = tempValue;
		}
		static void printArrayLn(int[] ar) {
            for (int n : ar) {
                System.out.print(n + " ");
            }
            System.out.print(System.lineSeparator());
        }

        public static void main(String[] args) {
            try (Scanner in = new Scanner(System.in)) {
                int n = in.nextInt();
                int[] ar = new int[n];
                for (int i = 0; i < n; i++) {
                    ar[i] = in.nextInt();
                }
                quicksort(ar, 0, ar.length -1);
            }
        }
    }

    public static void main(String[] args) {
        Solution.main(null);
    }
}

@@ -519,18 +519,24 @@
 on %7B%0D%0A%0D%0A
-%09%09
+        
 public s
@@ -588,19 +588,28 @@
 igh) %7B%0D%0A
-%09%09%09
+            
 if (low 
@@ -619,20 +619,32 @@
 igh) %7B%0D%0A
-%09%09%09%09
+                
 int pivo
@@ -675,28 +675,40 @@
 ow, high);%0D%0A
-%09%09%09%09
+                
 quicksort(ar
@@ -730,17 +730,30 @@
 ex -
+ 
 1);%0D%0A
-%09%09%09%09
+                
 quic
@@ -774,16 +774,17 @@
 tIndex +
+ 
 1, high)
@@ -790,17 +790,34 @@
 );%0D%0A
-%09%09%09%7D%0D%0A%09%09%7D
+            %7D%0D%0A        %7D%0D%0A
 %0D%0A  
@@ -886,25 +886,28 @@
  %7B%0D%0A        
-%09
+    
 int pivotVal
@@ -926,25 +926,28 @@
 %5D;%0D%0A        
-%09
+    
 int i = low;
@@ -956,17 +956,20 @@
         
-%09
+    
 for (int
@@ -1004,18 +1004,24 @@
         
-%09%09
+        
 if (ar%5Bj
@@ -1048,19 +1048,28 @@
         
-%09%09%09
+            
 swap(ar,
@@ -1089,18 +1089,28 @@
     
-%09%09%09
+            
 i = i +
+ 
 1;%0D%0A
@@ -1117,18 +1117,24 @@
         
-%09%09
+        
 %7D%0D%0A     
@@ -1136,17 +1136,20 @@
         
-%09
+    
 %7D%0D%0A     
@@ -1151,17 +1151,20 @@
         
+ 
-%09
+   
 swap(ar,
@@ -1183,17 +1183,20 @@
         
-%09
+    
 printArr
@@ -1214,17 +1214,20 @@
         
-%09
+    
 return i
@@ -1312,17 +1312,20 @@
         
-%09
+    
 int temp
@@ -1345,25 +1345,28 @@
 %5D;%0D%0A        
+   
-%09
+ 
 ar%5Bi1%5D = ar%5B
@@ -1379,17 +1379,20 @@
         
-%09
+    
 ar%5Bi2%5D =
@@ -1408,15 +1408,29 @@
 e;%0D%0A
-%09%09%7D%0D%0A%09%09
+        %7D%0D%0A%0D%0A        
 stat
@@ -1961,16 +1961,17 @@
 length -
+ 
 1);%0D%0A   

Format QuicksortInPlace