Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void quickSort(int arr[], int left, int right);
- int main() {
- int arr[10] = {4, 923, 95, 382, 2903, 90, 37, 29, 637, 439};
- quickSort(arr, 0, 9);
- for (int i = 1; i <= 10; i++) {
- cout << "Index " << i < "= " << arr[i] << endl;
- }
- }
- void quickSort(int arr[], int left, int right) {
- int i = left;
- int j = right;
- int tmp;
- int pivot = arr[(left+right)/2];
- while (i <= j) {
- while (arr[i] > pivot) i++;
- while (arr[j] < pivot) j++;
- if (i <= j) {
- tmp = arr[i];
- arr[i] = arr[j];
- arr[j] = tmp;
- i++;
- j++;
- }
- }
- if (left < j) quickSort(arr, left, j);
- if (right > i) quickSort(arr, i, right);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement