-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDoubleLL.cpp
149 lines (149 loc) · 3.4 KB
/
DoubleLL.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
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
#include<iostream>
using namespace std;
class student
{
public:
string rollno;
string sapid;
string name;
string specialization;
student *next;
student *prev;
student()
{
rollno="R171217041";
sapid="500060720";
name="Nishkarsh Raj Khare";
specialization="DevOps";
}
void insert()
{
cout<<"Enter the name of the person"<<endl;
cin>>name;
cout<<"Enter the sapid of the student"<<endl;
cin>>sapid;
cout<<"Enter the rollno of the student"<<endl;
cin>>rollno;
cout<<"Enter the Specialization of the student"<<endl;
cin>>specialization;
}
void show()
{
cout<<"Name of the student is :"<<name<<endl;
cout<<"Roll Number of the student is :"<<rollno<<endl;
cout<<"Sapid of the student is :"<<sapid<<endl;
cout<<"Specialization of the student is :"<<specialization<<endl;
}
};
int main()
{
cout<<"Hello! This is a code of Double Linked List on Student's Data"<<endl;
//Creation of first node
student *node,*ptr,*p,*start;
node=new student;
cout<<"Lets insert the first node data"<<endl;
node->insert();
node->next=NULL;
node->prev=NULL;
cout<<"Lets see the details of first node"<<endl;
node->show();
start=node;
string n,n2;
int flag=0;
int quit=0,choice;
do
{
cout<<"\t\t\t\tOption Menu\n\n"<<endl;
cout<<"1) Insertion at Beginning"<<endl;
cout<<"2) Insertion at End"<<endl;
cout<<"3) Insertion at any point"<<endl;
cout<<"4) Deletion at Beginning"<<endl;
cout<<"5) Deleltion at end"<<endl;
cout<<"6) Deletion at any point"<<endl;
cout<<"7) Traversal of nodes from start"<<endl;
cout<<"8) Traversal of nodes from last"<<endl;
cout<<"9) Quit"<<endl;
cout<<"Enter your choice"<<endl;
cin>>choice;
switch(choice)
{
case 1: cout<<"Insertion at Beginning"<<endl;
ptr=new student;
ptr->insert();
start->prev=ptr;
ptr->next=start;
ptr->prev=NULL;
start=ptr;
break;
case 2: cout<<"Insertion at End"<<endl;
node=new student;
node->insert();
node->next=NULL;
for(ptr=start;ptr->next!=NULL;ptr=ptr->next);
ptr->next=node;
node->prev=ptr;
break;
case 3: cout<<"Insertion at any point"<<endl;
cout<<"Enter the name of the student after which you want to make the insertion"<<endl;
cin>>n;
for(ptr=start;ptr!=NULL;ptr=ptr->next)
{
if(ptr->name==n)
break;
}
node=new student;
node->insert();
p=ptr->next;
node->next=ptr->next;
node->prev=p->prev;
ptr->next=node;
break;
case 4: cout<<"Deletion at beginning"<<endl;
ptr=start;
start=ptr->next;
delete ptr;
break;
case 5: cout<<"Deletion at End"<<endl;
for(ptr=start;ptr->next!=NULL;p=ptr,ptr=ptr->next);
delete ptr;
p->next=NULL;
break;
case 6: cout<<"Deletion anywhere"<<endl;
cout<<"Enter name of the student whose record you want to delete"<<endl;
cin>>n2;
for(ptr=start;ptr->next!=NULL;p=ptr,ptr=ptr->next)
{
if(ptr->name==n2)
{
flag=1;
break;
}
if(flag==1)
{
cout<<"Record Does not exist"<<endl;
}
else
{
p->next=ptr->next;
delete ptr;
}
}
break;
case 7: cout<<"Traversal from start"<<endl;
for(ptr=start;ptr!=NULL;ptr=ptr->next)
ptr->show();
break;
case 8: cout<<"Traversal from the end"<<endl;
for(ptr=start;ptr->next!=NULL;ptr=ptr->next);
for(;ptr!=NULL;ptr=ptr->prev)
{
ptr->show();
}
break;
case 9: quit=1;
break;
default: cout<<"Wrong Choice! Please Try Again"<<endl;
}
}while(quit!=1);
return 0;
}