Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include "Bubble_Sort_Proj.h"
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int n;
  10. bool correct = false;
  11.  
  12. if (correct == false)
  13. {
  14. cout << "Choose your bubble sorter (Enter '1' to pick your array OR '2' for random numbers!): ";
  15. cin >> n;
  16.  
  17. if (n == 1)
  18. {
  19. correct = true;
  20. int arraySize;
  21.  
  22. cout << "Enter the size of array: ";
  23. cin >> arraySize;
  24. int numArray[1000], a, b;
  25.  
  26. cout << "Enter the array values: ";
  27.  
  28. for (a = 0; a < arraySize; a++)
  29. {
  30. cin >> numArray[a];
  31. }
  32.  
  33. for (a = 1; a < arraySize - 1; a++)
  34. {
  35. for (b = 0; b < (arraySize - a - 1); b++)
  36. {
  37. if (numArray[b] > numArray[b + 1])
  38. {
  39. int tNum = numArray[b];
  40. numArray[b] = numArray[b + 1];
  41. numArray[b + 1] = tNum;
  42. }
  43. }
  44.  
  45. cout << "Array with bubble sort complete: ";
  46.  
  47. for (a = 0; a < arraySize; a++)
  48. {
  49. cout << " " << numArray[a];
  50. correct = false;
  51. }
  52.  
  53. return 0;
  54. }
  55. }
  56.  
  57. if (n == 2)
  58. {
  59. correct = true;
  60. int oarraySize;
  61.  
  62. cout << "Enter the size of the Random number array: ";
  63. cin >> oarraySize;
  64. int onumArray[100], c, d;
  65.  
  66. cout << "Random array values: " << endl;
  67.  
  68. for (c = 0; c < oarraySize; c++)
  69. {
  70. int numList = rand() % 100 + 1;
  71. onumArray[c] = numList;
  72.  
  73. cout << numList << endl;
  74. }
  75.  
  76. for (c = 1; c < oarraySize - 1; c++)
  77. {
  78. for (d = 0; d < (oarraySize - c - 1); d++)
  79. {
  80. if (onumArray[d] > onumArray[d + 1])
  81. {
  82. int temp = onumArray[d];
  83. onumArray[d] = onumArray[d + 1];
  84. onumArray[d + 1] = temp;
  85. }
  86. }
  87.  
  88. cout << "Random array with bubble sort complete: ";
  89.  
  90. for (c = 0; c < oarraySize; c++)
  91. {
  92. cout << " " << onumArray[c];
  93. correct = false;
  94. }
  95.  
  96. return 0;
  97. }
  98. }
  99. if (n >= 3)
  100. {
  101. correct = false;
  102. cout << "Try again." << endl;
  103. cout << "Choose your bubble sorter (Enter '1' to pick your array OR '2' for random numbers!): ";
  104. }
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement