-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
150 lines (134 loc) · 4.39 KB
/
Main.cpp
File metadata and controls
150 lines (134 loc) · 4.39 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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <iostream>
#include "Stack/Stack as array.cpp"
#include "Stack/Stack as linkedList.cpp"
#include "Queue/Queue as array.cpp"
#include "Queue/Queue as LinkedList.cpp"
#include "LinkedList/LinkedList.cpp"
#include "LinkedList/DoublyLinkedList.cpp"
#include "ArrayList/ArrayList.h"
using namespace std;
int main(){
cout << "===============================================" << endl;
cout << " DATA STRUCTURES - COMPREHENSIVE TESTS " << endl;
cout << "===============================================" << endl;
// ==================== STACK AS ARRAY ====================
cout << "\n\n=== TESTING STACK (ARRAY IMPLEMENTATION) ===" << endl;
Stack s;
s.push(10);
s.push(20);
s.push(30);
s.printStack();
cout << "Peek: " << s.peek() << endl;
s.pop();
s.printStack();
s.pop();
s.printStack();
s.pop();
s.printStack(); // Should be empty
// ==================== STACK AS LINKED LIST ====================
cout << "\n\n=== TESTING STACK (LINKED LIST IMPLEMENTATION) ===" << endl;
StackAsLinkedList sll;
sll.push(100);
sll.push(200);
sll.push(300);
sll.printStack();
cout << "Peek: " << sll.peek() << endl;
sll.pop();
sll.printStack();
sll.pop();
sll.printStack();
sll.pop();
sll.printStack(); // Should be empty
// ==================== QUEUE AS ARRAY ====================
cout << "\n\n=== TESTING QUEUE (ARRAY IMPLEMENTATION) ===" << endl;
Queue q;
q.Enqueue(5);
q.Enqueue(15);
q.Enqueue(25);
q.Display();
q.Dequeue();
q.Display();
q.Dequeue();
q.Display();
q.Dequeue();
q.Display(); // Should be empty
cout << "\n--- Testing Queue Array Resizing ---" << endl;
for(int i = 0; i < 12; i++)
q.Enqueue(i * 10);
q.Display();
// ==================== QUEUE AS LINKED LIST ====================
cout << "\n\n=== TESTING QUEUE (LINKED LIST IMPLEMENTATION) ===" << endl;
QueueAsLinkedList qll;
qll.Enqueue(7);
qll.Enqueue(14);
qll.Enqueue(21);
qll.printList();
qll.Dequeue();
qll.printList();
qll.Dequeue();
qll.printList();
qll.Dequeue();
qll.printList(); // Should be empty
// ==================== SINGLY LINKED LIST ====================
cout << "\n\n=== TESTING SINGLY LINKED LIST ===" << endl;
LinkedList ll;
cout << "Inserting at start..." << endl;
ll.insertAthestart(50);
ll.insertAthestart(40);
ll.insertAthestart(30);
cout << "Inserting at end..." << endl;
ll.insertAtTheEnd(60);
ll.insertAtTheEnd(70);
ll.printList();
cout << "Deleting at start..." << endl;
ll.deleteAtTheStart();
ll.printList();
cout << "Deleting at end..." << endl;
ll.deleteAtTheEnd();
ll.printList();
cout << "Deleting element with value 50..." << endl;
ll.deletewithval(50);
ll.printList();
// ==================== DOUBLY LINKED LIST ====================
cout << "\n\n=== TESTING DOUBLY LINKED LIST ===" << endl;
DoublyLinkedList dll;
cout << "Inserting at start..." << endl;
dll.insertAtTheStart(100);
dll.insertAtTheStart(90);
dll.insertAtTheStart(80);
cout << "Inserting at end..." << endl;
dll.insertAtTheEnd(110);
dll.insertAtTheEnd(120);
dll.printList();
cout << "Deleting at start..." << endl;
dll.deleteAtTheStart();
dll.printList();
cout << "Deleting at end..." << endl;
dll.deleteAtTheEnd();
dll.printList();
// ==================== ARRAY LIST ====================
cout << "\n\n=== TESTING ARRAY LIST (DYNAMIC) ===" << endl;
ArrayList<int> al;
cout << "Adding elements..." << endl;
al.add(1);
al.add(2);
al.add(3);
al.add(4);
al.add(5);
al.print();
cout << "Getting element at index 2: " << al.get(2) << endl;
cout << "Setting element at index 2 to 99..." << endl;
al.set(2, 99);
al.print();
cout << "Adding element 10 at index 1..." << endl;
al.add(1, 10);
al.print();
cout << "Removing element at index 3..." << endl;
al.remove(3);
al.print();
cout << "Size: " << al.getSize() << ", Capacity: " << al.getCapacity() << endl;
cout << "\n\n===============================================" << endl;
cout << " ALL TESTS COMPLETED SUCCESSFULLY " << endl;
cout << "===============================================" << endl;
return 0;
}