SHARE
TWEET

Untitled

a guest Jun 16th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void quicksort(int a[ ]) {
  2. StackhPair <Integer ,Integer> = stack = new Stack<>();
  3. stack.push(new Pair hInteger ,Integer i(1, a.length − 1));
  4. int min = 0;
  5. for(int i = 1; i < a.length; i++) if(a[i] < a[min]) min = i;
  6. int t = a[0]; a[0] = a[min]; a[min] = t;
  7. while(!stack.isempty()) {
  8. Pair hInteger ,Integer i p = stack.pop();
  9. int l = p.first(), r = p.second();
  10. int i = l − 1, j = r , pivot = j;
  11. do {
  12. do { i++; } while(a[i] < a[pivot]);
  13. do { j−−; } while(a[j] > a[pivot]);
  14. t = a[i]; a[i] = a[j]; a[j] = t;
  15. } while(i < j);
  16. a[j] = a[i]; a[i] = a[r ]; a[r ] = t;
  17. if(r − i > 1) stack.push(new Pair hInteger ,Integer i(i + 1, r ));
  18. if(i − l > 1) stack.push(new Pair hInteger ,Integer i(l, i − 1));
  19. }
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top