-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDCLLtraverse.cpp
72 lines (71 loc) · 1.34 KB
/
DCLLtraverse.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
#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 Circular linklist ^~^\n");
while(choice)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter data : ");
scanf("%d",&newnode->data);
newnode->next=0;
if(head==0)
{
head=tail=newnode;
head->next=head;
head->prev=head;
}
else
{
tail->next=newnode;
newnode->prev=tail;
newnode->next=head;
head->prev=newnode;
tail=newnode;
}
printf("Do U want to continue 1/0 : ");
scanf("%d",&choice);
}
printf("\nFor Conformation list : \tStarts From : (%d",tail->next->data);
printf(")\tAnd End At : (%d",tail->data);
printf(")\n");
}
Display()
{
struct node*temp;
int count=1;
temp = head;
printf("\nCreated a Doubly Circular linklist : ");
while(temp!=tail)
{
printf("%d->",temp->data);
temp = temp->next;
count++;
}
printf("%d",temp->data);
printf("\nTotal no. of nodes : %d",count);
}
//count the no. of nodes
int Getcount(struct node *head)
{
// Base case
if(head==0)
return 0;
//count is 1 + count of remaining list
return 1+Getcount(head->next);
}
int main()
{
CreateDLL();
Display();
return 0;
}