Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void swapValues(int *ElementA,int *ElementB);
- void quicksort(int t[], int p, int q);
- int partition(int t[], int p, int q);
- #define ARRAY_SIZE 17
- void displayArray(int t[],int size)
- {
- printf("\n");
- for(int i = 0; i < size; i ++)
- {
- printf("%d ",t[i]);
- }
- }
- int main ( void )
- {
- int t[] = { 9, 2, 4, 7, 3, 1, -5, 6, 5, 8, 3, -9, -2, -6, -7, -3, 0 };
- displayArray(t, 17);
- partition(t,0,16);
- //quicksort(t,0,16);
- displayArray(t, 17);
- getchar();
- return 0;
- }
- void quicksort(int t[], int p, int q)
- {
- if(p < q)
- {
- int r = partition(t,p,q);
- quicksort(t,p,r-1);
- quicksort(t,r+1,q);
- }
- }
- int partition(int t[], int p, int q)
- {
- int x = t[q];
- printf("pivot: %d",x);
- int i = p, j;
- for(j = p + 1; j < q; j++)
- {
- if(t[j] < x)
- {
- swapValues(&t[j],&t[i]);
- i++;
- }
- }
- swapValues(&t[i],&t[q]);
- return i;
- }
- void swapValues(int *ElementA,int *ElementB)
- {
- int temp = *ElementA;
- *ElementA = *ElementB;
- *ElementB = temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement