Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. void qsort(int array[], int start, int end){
  2.  
  3. int temp_start = start, temp_end = end;
  4. int part = array[start];
  5.  
  6. if(start >= end){
  7. return;
  8. }
  9.  
  10. while(temp_end > temp_start){
  11. for(temp_end; array[temp_end] >= array[temp_start] && temp_end > temp_start; temp_end --);
  12.  
  13. array[temp_start] = array[temp_end];
  14.  
  15. for(temp_start; array[temp_start] < part && temp_end > temp_start; temp_start++);
  16.  
  17. array[temp_end] = array[temp_start];
  18. }
  19.  
  20. array[temp_start] = part;
  21.  
  22. qsort(array, start, temp_start);
  23. qsort(array, temp_start, end);
  24. }
  25.  
  26. #define MAX 7
  27. #define START_POS 0
  28. #define END_POS (MAX - 1)
  29.  
  30. void qsort(int array[], int start, int end);
  31. void show(int array[], int size);
  32. void random_input(int array[], int size);
  33.  
  34. int main(){
  35. int array[MAX];
  36.  
  37. random_input(array, MAX);
  38. show(array, MAX);
  39. qsort(array, START_POS, END_POS);
  40. show(array, MAX);
  41.  
  42. return 0;
  43. }
  44.  
  45. 7 8
  46.  
  47. 7
  48.  
  49. qsort(array, temp_start, end)
  50.  
  51. 7 8
  52.  
  53. 7
  54.  
  55. 7 8
  56.  
  57. qsort(array, temp_start + 1, end);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement