// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.*;

public class Sorting {
   private static void qsint_help(int n1, int n2, int[] ia) {
      int tmp;
      int l = n1;
      int r = n2;
      int pivot = ia[(n1 + n2) / 2];
      do {
         /*
         while (ia[l] < pivot)
            l++;
         while (ia[r] > pivot)
            r--;
         */
         while (ia[l] > pivot)
            l++;
         while (ia[r] < pivot)
            r--;
         if (l <= r) {
            tmp = ia[l];
            ia[l] = ia[r];
            ia[r] = tmp;
            l++;
            r--;
         }
      } while (l <= r);
      if (n1 < r)
         qsint_help(n1, r, ia);
      if (l < n2)
         qsint_help(l, n2, ia);
      return;
   }
   public static void qsint(int[] ia) {
      qsint_help(0, ia.length - 1, ia);
      return;
   }
   public static void main(String[] args) {
      int[] ia = { 4, 7, 6, 2, 9, 1, 3, 5, 8, 0 };
      int[] ia1 = (int[]) ia.clone();
      Arrays.sort(ia1);
      System.out.println("Indbygget");
      for (int i = 0; i < ia1.length; i++) {
         System.out.println(ia1[i]);
      }
      int[] ia2 = (int[]) ia.clone();
      qsint(ia2);
      System.out.println("Egen");
      for (int i = 0; i < ia2.length; i++) {
         System.out.println(ia2[i]);
      }
   }
}
