Any particular language? Here's one implementation in Java paraphrased from Robert Sedgewicks data structure's book:
Code:static void quicksort(ITEM[] a, int l, int r) { Stack S = new Stack(50); S.push(l); S.push(r); while (!S.empty()) { r = S.pop(); l = S.pop(); if (r <= l) continue; int i = partition(a, l, r); if (i-l > r-i) { S.push(l); S.push(i-1); } S.push(i+1); S.push(r); if (r-i >= i-l) { S.push(l); S.push(i-1); } } }




Reply With Quote