-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLabCycle1-3Demo.cpp
91 lines (85 loc) · 2.91 KB
/
LabCycle1-3Demo.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
#include "LabCycle1-3.cpp"
using namespace std;
int main() {
Array<int> arr;
int 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. Left Rotate\n";
cout << "10. Right Rotate\n";
cout << "11. Frequency Count\n";
cout << "12. Count Distinct Elements\n";
cout << "0. 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:
arr.leftRotate();
cout << "Array left rotated." << endl;
break;
case 10:
arr.rightRotate();
cout << "Array right rotated." << endl;
break;
case 11:
cout << "Enter element to find its frequency: ";
cin >> a;
cout << "Frequency of element: " << arr.frequencyCount(a) << endl;
break;
case 12:
cout << "Number of distinct elements: " << arr.countDistinct() << endl;
break;
case 0:
cout << "Exiting...";
break;
default:
cout << "Invalid choice. Please enter again." << endl;
}
} while (choice != 0);
return 0;
}