Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #define size 9
- void alter(int *a,int*b)
- {
- int temp;
- temp=*a;
- *a=*b;
- *b=temp;
- }
- void sort(int *low,int *high)
- {
- int i;
- int *left,*right;
- left = low+1;
- right = high;
- if(right-left == 0)
- {
- if(*low>*left){
- alter(low,left);
- }
- }
- while(right- left > 0)
- {
- if(*left>*right){
- alter(left,right);
- }
- if(*right>*low){
- right--;
- }
- if(*left<*low){
- left++;
- }
- }
- if( high - low <= 1)return;
- sort(low, right);
- sort(right, high);
- }
- int main()
- {
- int arr[size+1]={3,6,5,4,8,1,7,4,11,100},i;
- sort(arr,arr+size);
- for(i=0;i<size;i++)
- printf("%d ",arr[i]);
- printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement