-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinklist.cpp
More file actions
123 lines (99 loc) · 1.92 KB
/
linklist.cpp
File metadata and controls
123 lines (99 loc) · 1.92 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
#include<iostream>
using namespace std;
//template<class T>
class linklist
{
public:
int info;
linklist *next;
};
class node
{
public:
linklist *root;
void insert(linklist *ptr)
{
linklist *temp;
int c=0;
do
{
temp=new linklist;
cout<<"\nenter the no to be inserted:";
cin>>temp->info;
if(ptr==NULL)
{
root=temp;
root->next=NULL;
ptr=temp;
}
else
{
ptr->next=temp;
ptr=temp;
temp->next=NULL;
}
cout<<"enter 1 for continue:";
cin>>c;
}while(c==1);
}
void display(linklist *ptr)
{
while(ptr!=NULL)
{
cout<<" "<<ptr->info;
ptr=ptr->next;
}
}
void del(linklist *ptr)
{
int x;
linklist *prev;
cout<<"enter the no which is deleted:";
cin>>x;
while(ptr!=NULL)
{
if(ptr->info==x)
{
if(ptr==root)
root=ptr->next;
else
{
prev->next=ptr->next;
}
delete (ptr);
break;
}
else
{
prev=ptr;
ptr=ptr->next;
}
}
}
};
int main()
{
node a;
a.root=NULL;
int c,x=1;
while(x!=0){
cout<<"\n\nlinklistlist list program"<<"\n\n1.insert"<<"\n2.display"<<"\n3.delete"<<"\nentr ur choice:";
cin>>c;
switch(c)
{
case 1:
a.insert(a.root);
break;
case 2:
a.display(a.root);
break;
case 3:
a.del(a.root);
break;
default:
cout<<"error:try agian"<<endl;
}
cout<<"\nenter 0 for exit:";
cin>>x;
}
}