Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include "Bubble_Sort_Proj.h"
- using namespace std;
- int main()
- {
- int n;
- bool correct = false;
- if (correct == false)
- {
- cout << "Choose your bubble sorter (Enter '1' to pick your array OR '2' for random numbers!): ";
- cin >> n;
- if (n == 1)
- {
- correct = true;
- int arraySize;
- cout << "Enter the size of array: ";
- cin >> arraySize;
- int numArray[1000], a, b;
- cout << "Enter the array values: ";
- for (a = 0; a < arraySize; a++)
- {
- cin >> numArray[a];
- }
- for (a = 1; a < arraySize - 1; a++)
- {
- for (b = 0; b < (arraySize - a - 1); b++)
- {
- if (numArray[b] > numArray[b + 1])
- {
- int tNum = numArray[b];
- numArray[b] = numArray[b + 1];
- numArray[b + 1] = tNum;
- }
- }
- cout << "Array with bubble sort complete: ";
- for (a = 0; a < arraySize; a++)
- {
- cout << " " << numArray[a];
- correct = false;
- }
- return 0;
- }
- }
- if (n == 2)
- {
- correct = true;
- int oarraySize;
- cout << "Enter the size of the Random number array: ";
- cin >> oarraySize;
- int onumArray[100], c, d;
- cout << "Random array values: " << endl;
- for (c = 0; c < oarraySize; c++)
- {
- int numList = rand() % 100 + 1;
- onumArray[c] = numList;
- cout << numList << endl;
- }
- for (c = 1; c < oarraySize - 1; c++)
- {
- for (d = 0; d < (oarraySize - c - 1); d++)
- {
- if (onumArray[d] > onumArray[d + 1])
- {
- int temp = onumArray[d];
- onumArray[d] = onumArray[d + 1];
- onumArray[d + 1] = temp;
- }
- }
- cout << "Random array with bubble sort complete: ";
- for (c = 0; c < oarraySize; c++)
- {
- cout << " " << onumArray[c];
- correct = false;
- }
- return 0;
- }
- }
- if (n >= 3)
- {
- correct = false;
- cout << "Try again." << endl;
- cout << "Choose your bubble sorter (Enter '1' to pick your array OR '2' for random numbers!): ";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement