5 //Swap integer values by array indexes
6 void swap(int a
, int b
)
13 //Partition the array into two halves and return the
14 //index about which the array is partitioned
15 int partition(int left
, int right
)
17 int pivotIndex
= left
;
18 int pivotValue
= array
[pivotIndex
];
22 swap(pivotIndex
, right
);
23 for(i
= left
; i
< right
; i
++)
25 if(array
[i
] < pivotValue
)
37 void quicksort(int left
, int right
)
42 int index
= partition(left
, right
);
43 quicksort(left
, index
- 1);
44 quicksort(index
+ 1, right
);
68 for (i
= 0; i
< 16; i
++)
69 printf("%d ", array
[i
]);
75 for (i
= 0; i
< 16; i
++)
76 printf("%d ", array
[i
]);
83 /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/