-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLabCycle1-2Demo.cpp
102 lines (96 loc) · 3.26 KB
/
LabCycle1-2Demo.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "LabCycle1-2.cpp"
int main() {
Array<int> arr;
char choice;
int a, pos;
do {
cout << "\nMenu:\n";
cout << "1. Insertion at Beginning\n";
cout << "2. Insertion at End\n";
cout << "3. Insertion at a specified position\n";
cout << "4. Deletion from Beginning\n";
cout << "5. Deletion from End\n";
cout << "6. Deletion from a specified position\n";
cout << "7. Find the index of a given element\n";
cout << "8. Display\n";
cout << "9. Linear Search\n";
cout << "a. Binary Search\n";
cout << "b. Bubble Sort\n";
cout << "c. Insertion Sort\n";
cout << "d. Selection Sort\n";
cout << "e. Merge Sort\n";
cout << "f. Quick Sort\n";
cout << "g. Quit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case '1':
cout << "Enter element to insert at beginning: ";
cin >> a;
arr.insertAtBeginning(a);
break;
case '2':
cout << "Enter element to insert at end: ";
cin >> a;
arr.insertAtEnd(a);
break;
case '3':
cout << "Enter position to insert element: ";
cin >> pos;
cout << "Enter element to insert: ";
cin >> a;
arr.insertAtPosition(pos, a);
break;
case '4':
arr.deleteFromBeginning();
break;
case '5':
arr.deleteFromEnd();
break;
case '6':
cout << "Enter position to delete element: ";
cin >> pos;
arr.deleteFromPosition(pos);
break;
case '7':
cout << "Enter element to find index: ";
cin >> a;
cout << "Index of element: " << arr.findIndex(a) << endl;
break;
case '8':
arr.display();
break;
case '9':
cout << "Enter element to search: ";
cin >> a;
cout << "Index of element (linear search): " << arr.linearSearch(a) << endl;
break;
case 'a':
cout << "Enter element to search: ";
cin >> a;
cout << "Index of element (binary search): " << arr.binarySearch(a) << endl;
break;
case 'b':
arr.bubbleSort();
break;
case 'c':
arr.insertionSort();
break;
case 'd':
arr.selectionSort();
break;
case 'e':
arr.mergeSort(0, arr.getSize() - 1);
break;
case 'f':
arr.quickSort(0, arr.getSize() - 1);
break;
case 'g':
cout << "Exiting...";
break;
default:
cout << "Invalid choice. Please enter again." << endl;
}
} while (choice != 'g');
return 0;
}