Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void swap(int i,int j, int *array)
- {
- int t = array[i];
- array[i] = array[j];
- array[j] = t;
- }
- int partition(int low, int high, int * array)
- {
- int i,j,t;
- i=j=low;
- t=0;
- while(j<high){
- if(array[j] < array[high]){
- swap(i,j, array);
- i++;
- }
- j++;
- }
- swap(i,high,array);
- return i;
- }
- void SelectSort(int n, int *array)
- {
- int j, k, i, t;
- j=n-1;
- while(j>0){
- k=j;
- i=j - 1;
- while(i>= 0){
- if(array[i]>array[k])
- k = i;
- i--;
- }
- swap(j,k,array);
- j--;
- }
- }
- void QuickSortRec(int m, int low, int high, int *array)
- {
- int f, q;
- if((high-low)>=m){
- f=partition(low, high, array);
- QuickSortRec(m, low, f-1, array);
- while(f+1<high){
- q=partition(f+1, high, array);
- QuickSortRec(m, f+1, q-1, array);
- f=q;
- }
- }
- else
- SelectSort(m, array);
- }
- int main()
- {
- int m, n, i;
- scanf("%d", &n);
- scanf("%d", &m);
- int array[n];
- for(i = 0; i < n; i++){
- scanf("%d", &array[i]);
- }
- QuickSortRec(m, 0, n-1, array);
- for(i = 0; i < n; i++)
- printf("%d ", array[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement