-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDLL.CPP
143 lines (113 loc) · 1.89 KB
/
DLL.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
#include<iostream.h>
#include<conio.h>
#include<malloc.h>
class cll
{ struct node
{
int data;
node *next;
};
node *start;
node *last;
public:
void input();
void display();
void del();
cll()
{
node *start=NULL;
}
node* create()
{
node *nnd;
nnd=(node *)malloc(sizeof(node));
return nnd;
}
}obj;//class ends
void cll::del()
{
node *del;
node *ptr;
cout<<"the data of node you want to delete ";
int dta;
cin>>dta;
ptr=obj.start;
while(ptr->next!=NULL&&ptr->data!=dta)
{ del=ptr;
ptr=ptr->next;
}
if(ptr==last)
{
//node *t=ptr;
del->next=NULL;
free(ptr);
// t->next=NULL;}
}
else if(ptr==start)
{ node *t=start;
start=start->next;
free(t);
}
else
{
node *t=ptr;
ptr=ptr->next;
del->next=ptr;
free(t);
}
}
void cll:: input()
{
node *in; node *trav;
in =create();
last=in;
cout<<"enter the data ";
cin>>in->data;
in->next=NULL;
if(start==NULL)
{ start=in;
}
else
{
trav=start;
while(trav->next!=NULL)
{
trav=trav->next;
}
trav->next=in;
}
}
void cll:: display()
{
node *prnt;
prnt=start;
while(prnt->next!=NULL)
{
cout<<prnt->data;
prnt=prnt->next;
}
cout<<prnt->data<<endl;
}
void main()
{
int ele;
clrscr();
cout<<"enter the no of ele you want ";
cin>>ele;
for(int i=0;i<ele;i++)
{
obj.input();
}
cout<<endl;
obj.display();
cout<<"how many nodes you want to delete ";
int no=0;
cin>>no;
for(i=0;i<no;i++)
{
obj.del();
}
cout<<endl;
obj.display();
getch();
}