-
Notifications
You must be signed in to change notification settings - Fork 1
/
doubly linkedlistt.cpp
86 lines (78 loc) · 962 Bytes
/
doubly linkedlistt.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
using namespace std;
#include<iostream>
struct node
{
int data;
struct node *prev;
struct node *next;
};
struct node* start =NULL;
struct node* createnode()
{
struct node *temp;
temp =new (struct node);
cin>>temp->data;
temp->prev=NULL;
temp->next=NULL;
return temp;
}
struct node* insertnode()
{
struct node *p,*temp;
temp=createnode();
p=start;
if(start==NULL)
{
start=temp;
temp->prev=NULL;
temp->next=NULL;
}
else
{
while(p->next!=NULL)
{
p=p->next;
}
temp->prev=p;
p->next=temp;
temp->next=NULL;
}
}
void addnode()
{
struct node *t,*p;
t=createnode();
if(start==NULL)
{
start=t;
t->next=NULL;
t->prev=NULL;
}
else
{
start->prev=t;
t->prev=NULL;
t->next=start;
start=t;
}
}
void traverse()
{
struct node *t;
t=start;
while(t->next!=NULL)
{
cout<<t->data<<endl;
t= t->next;
}
cout<<t->data;
}
int main()
{
for(int i=0;i<5;i++)
{
insertnode();
}
addnode();
traverse();
}