-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdoubly_circular_link_list.c
59 lines (55 loc) · 1.37 KB
/
doubly_circular_link_list.c
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
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node* pre;
struct node* next;
};
void display(struct node* head){
struct node*p = head;
do
{
printf("%d ",p->data);
p=p->next;
} while (p!=head);
// just for checking
printf("\n1st element is : ");
printf("%d",p->data);
}
struct node* create_doubly_circular_linllist(struct node * head){
int choice;
struct node * newnode;
struct node * temp;
// newnode->next = newnode->pre = NULL;
while (choice)
{
newnode = (struct node*)malloc(sizeof(struct node));
printf("Enter data : ");
scanf("%d",&newnode->data);
if (head==NULL)
{
head = temp = newnode;
temp->next = head;
temp->pre = head;
}
else
{
temp->next = newnode;
newnode->pre = temp;
newnode->next = head;
head->pre = newnode;
temp = newnode;
}
printf("Enter your choice : 1 for continue , 0 for break\n");
scanf("%d",&choice);
}
return head;
}
int main()
{
struct node * head = NULL;
head = create_doubly_circular_linllist(head);
display(head);
return 0;
}