-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCircularLinkedLists.cpp
64 lines (59 loc) · 1.15 KB
/
CircularLinkedLists.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
#include <iostream>
using namespace std;
struct Node {
int age;
string name;
struct Node *next;
};
struct Node* head = NULL;
void insert(int n, string s) {
struct Node* newnode = new Node;
struct Node *ptr = head;
newnode->age = n;
newnode->name = s;
newnode->next = head;
if (head!= NULL) {
while (ptr->next != head)
ptr = ptr->next;
ptr->next = newnode;
} else
newnode->next = newnode;
head = newnode;
}
void display() {
struct Node* temp;
temp = head;
cout << "Names:" << endl;
do {
cout<<temp->name <<" ";
temp = temp->next;
} while(temp != head);
temp = head;
cout << endl;
cout << "Ages:" << endl;
do {
cout<<temp->age <<" ";
temp = temp->next;
} while(temp != head);
}
int main(){
int i = -1;
string s;
int age;
while(i != 0){
cout << "ENTER\n1.INSERT AT THE START\n2.DISPLAY ALL ELEMENTS\n0.QUIT PROGRAM" << endl;
cin >> i;
switch(i){
case 1:
cout << "Enter Name And Age" <<endl;
cin >> s;
cin >> age;
insert(age,s);
break;
case 2:
display();
break;
}
}
return 0;
}