-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcircular_linklist_using_tail.c
110 lines (95 loc) · 2.3 KB
/
circular_linklist_using_tail.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
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
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
};
void display(struct node *tail)
{
struct node *p = tail;
do
{
p=p->next;
printf("%d->",p->data);
} while (p!=tail);
}
struct node *create_Circular_linklist(struct node *tail)
{
int choice;
struct node *newnode;
while (choice)
{
newnode = (struct node *)malloc(sizeof(struct node));
printf("Enter data : ");
scanf("%d", &newnode->data);
if (tail == NULL)
{
tail = newnode;
tail->next = newnode;
}
else
{
newnode->next = tail->next;
tail->next = newnode;
tail = newnode;
}
printf("Enter 1 for continue , 0 for exit\n");
scanf("%d", &choice);
}
return tail;
}
int main()
{
struct node *tail = NULL;
tail = create_Circular_linklist(tail);
display(tail);
return 0;
}
// #include <stdio.h>
// #include <stdlib.h>
// struct node
// {
// int data;
// struct node * next;
// };
// void display(struct node * head){
// struct node * p = head;
// do
// {
// printf("%d->",p->data);
// p=p->next;
// } while (p!=head);
// // for checking purpose
// // printf("Data is : %d",p->data);
// }
// struct node * create_Circular_linklist(struct node * head){
// int choice;
// struct node* newnode;
// struct node* temp;
// while (choice)
// {
// newnode = (struct node*)malloc(sizeof(struct node));
// printf("Enter data : ");
// scanf("%d",&newnode->data);
// if (head==NULL)
// {
// head=temp=newnode;
// }
// else{
// temp->next = newnode;
// temp=newnode;
// }
// temp->next = head;
// printf("Enter 1 for continue , 0 for exit\n");
// scanf("%d",&choice);
// }
// return head;
// }
// int main()
// {
// struct node * head = NULL;
// head = create_Circular_linklist(head);
// display(head);
// return 0;
// }