-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimplement_circular_ll.c
86 lines (75 loc) · 1.7 KB
/
implement_circular_ll.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
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
struct node
{
int data;
struct node *next;
} *head;
void create_cll();
void display_cll();
void main()
{
int choice = 0;
while(choice != 3)
{
printf("\nChoose your option : \
1. Create A Circular Linked List \
2. Display \
3. Exit\n");
scanf("%d", &choice);
switch (choice)
{
case 1:
create_cll();
break;
case 2:
display_cll();
break;
case 3:
printf("Exiting the program.\n");
break;
default:
printf("Invalid choice. Please choose again.\n");
}
}
}
void create_cll()
{
struct node *newnode, *temp;
head = NULL;
bool choice = true;
while (choice)
{
newnode = (struct node *) malloc(sizeof(struct node));
printf("Enter Data to Insert - ");
scanf("%d", &newnode -> data);
if (head == NULL)
head = temp = newnode;
else
{
temp -> next = newnode;
temp = newnode;
}
temp -> next = head;
printf("Do you want to continue? (1/0): ");
scanf("%d", &choice);
}
}
void display_cll()
{
struct node *ptr;
ptr = head;
if (ptr == NULL)
printf("Nothing to Print!\n");
else
{
printf("\nPrinting the Elements :- \n");
do
{
printf("\n%d", ptr->data);
ptr = ptr->next;
} while (ptr != head);
printf("\n");
}
}