Advertisement
lily09290110

quickly sort

Jan 5th, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #define size 9
  4. void alter(int *a,int*b)
  5. {
  6. int temp;
  7. temp=*a;
  8. *a=*b;
  9. *b=temp;
  10. }
  11. void sort(int *low,int *high)
  12. {
  13. int i;
  14.  
  15. int *left,*right;
  16. left = low+1;
  17. right = high;
  18. if(right-left == 0)
  19. {
  20. if(*low>*left){
  21. alter(low,left);
  22. }
  23. }
  24.  
  25. while(right- left > 0)
  26. {
  27. if(*left>*right){
  28. alter(left,right);
  29. }
  30. if(*right>*low){
  31. right--;
  32. }
  33. if(*left<*low){
  34. left++;
  35. }
  36. }
  37.  
  38. if( high - low <= 1)return;
  39. sort(low, right);
  40. sort(right, high);
  41. }
  42. int main()
  43. {
  44. int arr[size+1]={3,6,5,4,8,1,7,4,11,100},i;
  45. sort(arr,arr+size);
  46. for(i=0;i<size;i++)
  47. printf("%d ",arr[i]);
  48. printf("\n");
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement