Advertisement
Guest User

Sort used

a guest
Jul 27th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. void Sort(int li, int ls, int v[])
  2. {
  3. int min, max, m, temp;
  4. min = li;
  5. max = ls;
  6. m = v[(li + ls) / 2];
  7. cout << "THIS IS THE " << i2 << " PASS THROUGH THIS FUNCTION" << endl << endl;
  8. i2++;
  9. cout << "Min is:" << min << endl;
  10. cout << "Max is:" << max << endl;
  11. cout << "M is:" << m << endl;
  12. while (min <= max)
  13. {
  14. cout << "Min is <= max and is:" << min << endl;
  15. cout << "Max is >= min and is:" << max << endl;
  16. while (v[min] > m) {
  17. min++;
  18. cout << "New min is:" << min << " " << "because v[min]=" << v[min-1] << " is > m: " << m << endl;
  19. };
  20. while (v[max] < m)
  21. {
  22. max--;
  23. cout << "New max is:" << max << " " << "because v[max]=" << v[max+1] << " is < m=" << m << endl;
  24. };
  25. if (min <= max)
  26. {
  27. cout << "This is happening because min=" << min << " is <= than max=" << max << endl;
  28. temp = v[min];
  29. cout << "This is v[min] before it's changed: " << v[min] << " and this is v[max] before: " << v[max] << endl;
  30. v[min++] = v[max];
  31. v[max--] = temp;
  32. cout << "This is v[min] after it's changed: " << v[min] << " this is v[max] after change: " << v[max] << endl;
  33. cout << "This is max: " << max << " and this is min: " << min << endl;
  34. };
  35. };
  36. cout << "The new array is: " << endl;
  37. for (i = 1; i <= k; i++)
  38. cout << v[i] << " ";
  39. cout << endl;
  40. cout << "This is li: " << li << " and this is ls: " << ls << endl;
  41. if (li < max)
  42. {
  43. cout << "This is happening because li < max therefor: " << li << " < " << max << endl << endl;
  44. Sort(li, max, v);
  45. };
  46. if (ls > min)
  47. {
  48. cout << "This is happening because ls > min therefor: " << ls << " > " << min << endl << endl;
  49. Sort(min, ls, v);
  50. };
  51. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement