-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsert_Node_Beginning_Circular_Linked_List.c
More file actions
92 lines (84 loc) · 2.05 KB
/
Insert_Node_Beginning_Circular_Linked_List.c
File metadata and controls
92 lines (84 loc) · 2.05 KB
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
// Insert Node beginning of Circular Linked List
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
struct node *tail = NULL, *newnode = NULL, *temp = NULL;
void create_Circular_Linked_List();
void display_list();
void insert_node_beginning_of_Linked_List();
int main()
{
create_Circular_Linked_List();
display_list();
insert_node_beginning_of_Linked_List();
display_list();
return 0;
}
void create_Circular_Linked_List()
{
int choice = 1;
while(choice==1)
{
newnode = (struct node *)malloc(sizeof(struct node));
if(newnode==NULL)
printf("Memory Not Allocate.");
else
{
printf("Enter data of Node\n");
scanf("%d", &newnode->data);
newnode->next = NULL;
if(tail==NULL)
{
tail = newnode;
tail->next = newnode;
}
else
{
newnode->next = tail->next;
tail->next = newnode;
tail = newnode;
}
}
printf("Do You Want to insert another node in Linked List? if yes press 1 else press 0\n");
scanf("%d", &choice);
}
}
void display_list()
{
if(tail==NULL)
printf("Linked List is Empty.");
else
{
temp = tail->next;
printf("\nThe Elements of Linked List are\n");
while (temp != tail)
{
printf("%d ", temp->data);
temp = temp->next;
}
printf("%d", temp->data);
}
}
void insert_node_beginning_of_Linked_List()
{
if(tail==NULL)
printf("Linked List is Empty.");
else
{
newnode = (struct node *)malloc(sizeof(struct node));
if (newnode == NULL)
printf("\nMemory Not Allocate for New Node.\n");
else
{
printf("\nEnter data for Newly Created Node\n");
scanf("%d", &newnode->data);
temp = tail->next;
newnode->next = temp;
tail->next = newnode;
}
}
}