Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void quicksort(int a[ ]) {
- StackhPair <Integer ,Integer> = stack = new Stack<>();
- stack.push(new Pair hInteger ,Integer i(1, a.length − 1));
- int min = 0;
- for(int i = 1; i < a.length; i++) if(a[i] < a[min]) min = i;
- int t = a[0]; a[0] = a[min]; a[min] = t;
- while(!stack.isempty()) {
- Pair hInteger ,Integer i p = stack.pop();
- int l = p.first(), r = p.second();
- int i = l − 1, j = r , pivot = j;
- do {
- do { i++; } while(a[i] < a[pivot]);
- do { j−−; } while(a[j] > a[pivot]);
- t = a[i]; a[i] = a[j]; a[j] = t;
- } while(i < j);
- a[j] = a[i]; a[i] = a[r ]; a[r ] = t;
- if(r − i > 1) stack.push(new Pair hInteger ,Integer i(i + 1, r ));
- if(i − l > 1) stack.push(new Pair hInteger ,Integer i(l, i − 1));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement