-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
59 lines (46 loc) · 1.49 KB
/
main.cpp
File metadata and controls
59 lines (46 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Main.cpp - Get Array size from the user, generate new array and sort it.
* Author: Michael Gosling
*/
#include <iostream>
#include "Sorter.h"
#include <regex>
int main() {
std::string userInput; // holds user input
std::regex reg("\\d+"); // validates user input
// while the userinput doesn't match the regex
while (!std::regex_match(userInput, reg)) {
// get array size from user
std::cout << "Enter an array size: ";
std::cin >> userInput;
if (!std::regex_match(userInput, reg))
std::cout << "Invalid input, try again" << std::endl; // if input is invalid, tell them.
}
// once input is valid, translate it to int.
int arraySize = stoi(userInput);
// create sorter
Sorter sorter(arraySize);
std::cout << std::endl;
// run bubble sort
std::cout << "_Bubble Sort_" << std::endl;
sorter.runSort(Bubble);
// run selection sort
std::cout << "_Selection Sort_" << std::endl;
sorter.runSort(Selection);
// run insertion sort
std::cout << "_Insertion Sort_" << std::endl;
sorter.runSort(Insertion);
// run shell sort
std::cout << "_Shell Sort_" << std::endl;
sorter.runSort(Shell);
// run quick sort
std::cout << "_Quick Sort_" << std::endl;
sorter.runSort(Quick);
// run merge sort
std::cout << "_Merge Sort_" << std::endl;
sorter.runSort(Merge);
// run radix sort
std::cout << "_Radix Sort_" << std::endl;
sorter.runSort(Radix);
return 0;
}