-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab 26 Oct Q1.cpp
More file actions
200 lines (158 loc) · 3.15 KB
/
Copy pathlab 26 Oct Q1.cpp
File metadata and controls
200 lines (158 loc) · 3.15 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include<iostream>
using namespace std;
class Node
{
public:
int ROLL;
Node *Link;
};
class LinkedList
{
private:
Node *head, *tail, *current, *temp;
public:
LinkedList()
{
head = NULL;
}
void InsertAtHead(int roll)
{
if (head == NULL)
{
head = new Node;
head->ROLL = roll;
head->Link = NULL;
tail = head;
}
else
{
temp = new Node;
temp->ROLL = roll;
temp->Link = head;
head = temp;
}
}
void InsertAtMid(int roll, int location)
{
current = head;
temp = new Node;
while(current != NULL)
{
if (location == current->ROLL)
{
temp->Link = current->Link;
current->Link = temp;
cout << "22316 inserted at 3rd location!\n\n";
}
current = current->Link;
}
return;
}
void InsertAtTail(int roll)
{
if (head == NULL)
{
InsertAtHead(roll);
return;
}
temp = new Node;
temp->ROLL = roll;
temp->Link = NULL;
tail->Link = temp;
tail = temp;
if (head == NULL)
{
head = tail;
}
}
void Display()
{
current = head;
cout << "\tROLL" << endl;
while(current != NULL)
{
cout << "\t" << current->ROLL << "\n";
current = current->Link;
}
cout << endl;
}
void Search(int roll)
{
bool found = false;
current = head;
int location = 1;
cout << endl;
while (current != NULL)
{
if (roll == current->ROLL)
{
found = true;
cout << "Roll found at " << location << "\n" << current->ROLL << "\n\n";
}
current = current->Link;
location += 1;
}
if (!found)
{
cout << "ROLL NO. not found!\n";
}
}
};
main()
{
LinkedList list;
int select, roll;
list.InsertAtHead(21222);
list.InsertAtTail(21223);
list.InsertAtTail(21224);
list.InsertAtTail(21225);
list.InsertAtTail(21227);
list.InsertAtTail(21228);
list.InsertAtTail(21231);
list.InsertAtTail(21235);
list.InsertAtTail(21236);
list.InsertAtTail(21237);
list.InsertAtTail(21238);
list.InsertAtTail(21239);
list.InsertAtTail(21240);
list.InsertAtTail(21242);
list.InsertAtTail(21245);
list.InsertAtTail(21247);
list.InsertAtTail(21250);
list.InsertAtTail(21251);
list.InsertAtTail(21252);
list.InsertAtTail(21257);
list.InsertAtTail(21258);
list.InsertAtTail(21263);
list.InsertAtTail(21112);
list.InsertAtTail(21094);
list.InsertAtTail(21126);
list.InsertAtTail(21131);
list.InsertAtTail(21102);
list.Display();
list.InsertAtMid(22316, 21223);
cout << "Updated Linked List\n";
list.Display();
cout << "WELCOME TO STUDENT DATA SYSTEM!\n\n";
while (true)
{
cout << "Press 1 to search for a record. \n";
cout << "Press 2 to display all records. \n";
cin >> select;
while (select != 1 && select != 2)
{
cout << "Wrong selection. Select again: ";
cin >> select;
}
if (select == 1)
{
cout << "Enter ROLL NO. of the sutdent to search: ";
cin >> roll;
list.Search(roll);
}
else if (select == 2)
{
list.Display();
}
}
}