#include <iostream> #include <stack> using namespace std;
A non-recursive version of a quick sort.
void Swap (int &a, int &b) {int temp = A;
A = b;
b = temp;
int Sort (int a[],int low,int high) {int i = low;
int j = high;
while (I < J) {while (I<j && A[j]>=a[high]) j--;
while (I < J && A[i] <= A[high]) i++;
if (I < j) {Swap (a[i],a[j]);
} if (A[j]>a[high]) Swap (A[j],a[high]);
Return J;
} void grial (int a[],int low,int high) {stack<int> st;
St.push (high);
St.push (Low);
while (st.empty () = = false) {int i = st.top ();
St.pop ();
Int J = St.top ();
St.pop ();
if (I < j) {int midindex = Sort (a,i,j);
St.push (j);
St.push (midindex+1);
St.push (Midindex);
St.push (i); int main () {int a[] = {6,5,3,3,-11, -1,-11,-11,129,3,21,3,421,-12};
Grial (A, 0, sizeof (a)/sizeof (int)-1);
for (int i = 0; i < sizeof (a)/sizeof (int); i++) {cout << a[i] << "";
} cout << Endl;
return 0; }
#include <iostream> using namespace std;
void Swap (int &a, int &b) {int temp = A;
A = b;
b = temp;
} void grial (int a[],int low,int high) {int i = low;
int j = high;
if (i >= j) return;
int temp = A[high];
while (I < J) {while (I < J && A[high] <= a[j]) j--;
while (I < J && A[high] >= a[i]) i++;
if (I < j) {Swap (a[i],a[j]);
} if (A[j]>a[high]) Swap (A[j],a[high]);
Grial (A, Low, j);
Grial (A, j + 1, high);
int main () {int a[] = {5,3,6,2,5,6,7,2,1,3,4,5,6,8,4,5,7,8,9,354,1,1,23, 4,6,7,7,3};
Grial (A, 0, sizeof (a)/sizeof (int)-1);
for (int i = 0; i < sizeof (a)/sizeof (int); i++) {cout << a[i] << "";
} cout << Endl;
return 0; }
#include <iostream> using namespace std; void Swap (int &a, int &b) {int temp = A;
A = b;
b = temp;
} void Qulick (int a[], int low, int high) {int i = low-1;
int j = Low;
if (low >= high) return;
while (J
#include <iostream> using namespace std;
The importance of the heap is self-evident, the maximum number of billions of data inside the largest 100,//can use the heap, the best efficiency.
Class Maxheap {public:maxheap (int a[],int n) {data = new Int[n];
for (int i = 0; i < n; i++) {data[i] = A[i];
size = N;
n = size/2;
Setheap (n);
} void Setheap (int n) {while (n--) {getset (data,n);
} void Getset (int a[],int n) {int i = n;
Int J = 2 * i + 1;
while (J < size) {if (j + 1 < size && A[j] > a[j + 1]) J = j + 1;
if (A[i]>a[j]) {a[i] ^= a[j];
A[J] ^= a[i];
A[i] ^= a[j];
} i = J;
j = i * 2 + 1;
} void Sort () {int *b = new Int[size-1];
int k = 0;
while (size) {b[k++] = data[0]; Data[0] = data[size-1];
size--;
Getset (data,0);
for (int i = 0; i < K; i++) {cout << b[i] << "";
} cout << Endl;
} Private:int *data;
int size;
};
int main () {int i = 0;
int a[20];
for (; i < i++) {A[i] = rand ()% 20;
cout << A[i] << "";
} cout << Endl;
Maxheap MH (A,sizeof (a)/sizeof (int)); Mh.
Sort ();
return 0;
}