-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDLLLtraversion.cpp
57 lines (55 loc) · 945 Bytes
/
DLLLtraversion.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
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
struct node *prev;
}*head,*tail;
void CreateDLL()
{
struct node*newnode;
int choice= 1;
head=0;
printf("Create a Doubly linklist ^~^\n");
while(choice)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter data : ");
scanf("%d",&newnode->data);
newnode->next=0;
if(tail==0)
{
head=tail=newnode;
}
else
{
tail->next=newnode;
newnode->prev=tail;
tail=newnode;
}
printf("Do U want to continue 1/0 : ");
scanf("%d",&choice);
}
}
Display()
{
struct node*temp;
int count=1;
temp = head;
printf("\nCreated a Doubly linklist : ");
while(temp->next!=0)
{
printf("%d->",temp->data);
temp = temp->next;
count++;
}
printf("%d",temp->data);
printf("\nTotal no. of nodes : %d",count);
}
int main()
{
CreateDLL();
Display();
return 0;
}