Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int i, j, array[], userSize;
  5. char ch;
  6. //void reverseSort();
  7.  
  8. int main()
  9. {
  10. cout << "How many integers would you like to sort? \n";
  11. cin >> userSize;
  12.  
  13.  
  14. int* array = new int[userSize];
  15.  
  16. for (i = 0; i < userSize; ++i)
  17. {
  18. cout << "Enter digit #" << i + 1 << ": " << endl;
  19. cin >> array[i];
  20. }
  21.  
  22. for (i = 0; i < userSize; ++i)
  23. {
  24. for (j = 0; j < userSize - i - 1; ++j)
  25. {
  26. if (array[j] < array[j + 1])
  27. {
  28. array[j] = array[j] + array[j + 1];
  29. array[j + 1] = array[j] - array[j + 1];
  30. array[j] = array[j] - array[j + 1];
  31. }
  32. }
  33. }
  34.  
  35.  
  36.  
  37. cout << "Here is that set of values; " << endl;
  38. for (i = 0; i < userSize; ++i)
  39. {
  40. cout << " > " << array[i];
  41. }
  42.  
  43. cout << "\nHere is that set in descending order;\n";
  44. for (i = 0; i < userSize; ++i)
  45. {
  46. cout << " > " << array[i];
  47. }
  48.  
  49.  
  50. delete[] array;
  51. cin.get();
  52. ch = cin.get();
  53. }
  54. /*
  55. void reverseSort()
  56. {
  57. userSize = userSizeREV;
  58. int* array = new int[userSize];
  59. for (i = 0; i < userSize; ++i)
  60. {
  61. for (j = 0; j < userSize - i - 1; ++j)
  62. {
  63. if (array[j] < array[j + 1])
  64. {
  65. array[j] = array[j] + array[j + 1];
  66. array[j + 1] = array[j] - array[j + 1];
  67. array[j] = array[j] - array[j + 1];
  68. }
  69. }
  70. }
  71.  
  72.  
  73. //end
  74. }
  75. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement