/* (p87) quick_sort: sort v[left]...v[right] into increasing order */ void quick_sort(int v[], int left, int right) { int i, last; if (left >= right) /* do nothing if array contains */ return; /* fewer than two elements */ swap_v(v, left, (left + right)/2); /* move partition elem */ last = left; /* to v[0] */ for (i = left+1; i <= right; i++) if (v[i] < v[left]) swap_v(v, ++last, i); swap_v(v, left, last); /* restore partition elem */ quick_sort(v, left, last-1); quick_sort(v, last+1, right); }
int main () { // integer int x=7; int y=9; cout << "Before the swap x = "<< x << ", y = "<<y <<endl; swap_v(x,y); cout << "After the swap x = "<< x << ", y = "<<y <<endl; swap_v(7,9); // const integer const int cx=7; const int cy=9; cout << "Before the swap cx = "<< cx << ", cy = "<<cy <<endl; swap_v(cx,cy); cout << "After the swap cx = "<< cx << ", cy = "<<cy <<endl; swap_v(7.7,9.9); // double double dx=7.7; double dy=9.9; cout << "Before the swap dx = "<< dx << ", dy = "<<dy <<endl; swap_v(dx,dy); cout << "After the swap dx = "<< dx << ", dy = "<<dy <<endl; swap_v(7.7,9.9); return 0; }