-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbCLLadd.cpp
More file actions
113 lines (112 loc) · 1.81 KB
/
dbCLLadd.cpp
File metadata and controls
113 lines (112 loc) · 1.81 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
//dbCLL add functions
#include<iostream>
using namespace std;
struct node
{
int data;
node*prev,*next;
};
node *first,*temp,*ttemp,*p;
void addnode()
{
ttemp=new node;
ttemp->next=ttemp->prev=nullptr;
cin>>ttemp->data;
if(first==nullptr)
{
first=ttemp;
ttemp->next=ttemp->prev=first;
}
else
{
temp->next=ttemp;
ttemp->prev=temp;
ttemp->next=first;
first->prev=ttemp;
}
temp=ttemp;
}
void add_after_first(int x)
{
temp=first->next;
ttemp=new node;
ttemp->data=x;
ttemp->prev=first;
ttemp->next=temp;
temp->prev=ttemp;
first->next=ttemp;
}
void add_before_first(int y)
{
temp=first->prev;
ttemp=new node;
ttemp->data=y;
ttemp->next=first;
first->prev=ttemp;
ttemp->prev=temp;
temp->next=ttemp;
first=ttemp;
}
void add_after_given(int x,int y)
{
temp=first;
while(temp->data!=x)
{
temp=temp->next;
}
p=temp->next;
ttemp=new node;
ttemp->data=y;
ttemp->prev=temp;
temp->next=ttemp;
ttemp->next=p;
p->prev=ttemp;
}
void add_before_given(int x,int y)
{
temp=first;
while(temp->data!=x)
{
temp=temp->next;
}
p=temp->prev;
ttemp=new node;
ttemp->data=y;
ttemp->next=temp;
temp->prev=ttemp;
p->next=ttemp;
ttemp->prev=p;
}
void disp()
{
temp=first;
do
{
cout<<temp->data<<"\n";
temp=temp->next;
}while(temp!=first);
}
int main()
{
first=temp=ttemp=nullptr;
int n;
cout<<"enter n: ";
cin>>n;
for(int i=0;i<n;i++)
addnode();
cout<<"\n";
disp();
cout<<"\n";
add_after_first(0);
disp();
cout<<"\n";
add_before_first(0);
disp();
cout<<"\n";
add_after_given(3,4);
disp();
cout<<"\n";
add_before_given(3,6);
disp();
cout<<"\n";
}