Skip to content

Instantly share code, notes, and snippets.

@attashe
Created February 19, 2018 18:36
Show Gist options
  • Save attashe/b40f397e3de7e00e923b45c9fdd49567 to your computer and use it in GitHub Desktop.
Save attashe/b40f397e3de7e00e923b45c9fdd49567 to your computer and use it in GitHub Desktop.
int RandomazerPartition(int* A, int p, int r) {
int q = rand() % (r - p) + p;
int j = 0;
int k = 0;
for (int i = p; i <= r; i++) {
if (A[i] < A[q]) {
A1[j] = A[i];
j++;
}
if(A[i] > A[q]) {
A2[k] = A[i];
k++;
}
}
int tn = A[q];
for (int i = 0; i < 3; i++) {
cout << endl;
}
for (int i = 0; i < j; i++) {
cout << A1[i] << " ";
}
for (int i = 0; i < 3; i++) {
cout << endl;
}
for (int i = 0; i < k; i++) {
cout << A2[i] << " ";
}
int i;
for (i = p; i <= p+j; i++) {
A[i] = A1[--j];
}
A[i] = tn;
i++;
for (; i <= r; i++) {
A[i] = A2[--k];
}
return q;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment