Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include<stdlib.h>
- void quicksort(int arr[], int low, int high);
- int main() {
- int array[10] ;
- int i,max;
- scanf("%d",&max);
- for(i = 0; i < max; i++)
- scanf("%d",&array[i]);
- printf("Before quicksort: ");
- for(i = 0; i < max; i++) {
- printf(" %d ", array[i]);
- }
- printf("\n");
- quicksort(array, 0, (max - 1));
- printf("After quicksort: ");
- for(i = 0; i < max; i++) {
- printf(" %d ", array[i]);
- }
- printf("\n");
- return 0;
- }
- void quicksort(int arr[], int low, int high) {
- int i = low;
- int j = high;
- int temp = 0;
- int z = arr[(low + high) / 2];
- do {
- while(arr[i] < z) i++;
- while(arr[j] > z) j--;
- if(i <= j)
- {
- temp = arr[i];
- arr[i] = arr[j];
- arr[j] = temp;
- i++;
- j--;
- }
- } while(i <= j);
- if(j> low )
- quicksort(arr, low, j);
- if(i < high)
- quicksort(arr, i, high);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement