-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCirculer_linklist.c
68 lines (64 loc) · 1.42 KB
/
Circuler_linklist.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
#include <stdio.h>
#include <stdlib.h>
struct Node
{
int data;
struct Node* next;
}*head;
void display(struct Node* head){
struct Node * temp;
if (head==NULL)
{
printf("Linklist is empty");
}
else
{
temp=head;
while (temp->next!=head)
{
printf("%d->",temp->data);
temp=temp->next;
}
printf("%d",temp->data);
printf("->NULL\n");
}
}
struct Node* CreateLinklist(){
int choice;
struct Node* newNode;
struct Node* p=NULL;
struct Node* temp=NULL;
head=NULL;
while (choice)
{
newNode=(struct Node*)malloc(sizeof(struct Node));
printf("Enter data: ");
scanf("%d",&newNode->data);
newNode->next=NULL;
if (head==NULL)
{
head=temp=newNode;
}
else
{
// p=head;
// while (p->next!=NULL)
// {
// p=p->next;
// }
// p->next=newNode;
temp->next=newNode;
temp=newNode;
}
temp->next=head;
printf("1 for continue, 0 for exit.\n");
scanf("%d",&choice);
}
return head;
}
int main()
{
head=CreateLinklist();
display(head);
return 0;
}