forked from Sai-02/Data-Structures-using-C
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircular_Linked_List.c
More file actions
62 lines (55 loc) · 1.14 KB
/
Circular_Linked_List.c
File metadata and controls
62 lines (55 loc) · 1.14 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
#include <stdio.h>
#include <stdlib.h>
struct node
{
int info;
struct node *link;
};
struct node *insertValue(struct node *, int);
int main()
{
int n;
scanf("%d", &n);
struct node *head = (struct node *)malloc(sizeof(struct node));
head->link = NULL;
struct node *temp;
for (int i = 0; i < n; i++)
{
int value;
scanf("%d", &value);
if (i == 0)
{
head->info = value;
temp = head;
}
else
{
struct node *new = (struct node *)malloc(sizeof(struct node));
new->info = value;
new->link = NULL;
temp->link = new;
temp = temp->link;
}
}
temp->link = head;
int k;
scanf("%d", &k);
return 0;
}
struct node *insertValue(struct node *head, int k)
{
struct node *new = (struct node *)malloc(sizeof(struct node *));
new->info = k;
new->link = NULL;
if (head == NULL)
{
new->link = new;
return new;
}
struct node *last = head;
while (last->link != head)
{
last = last->link;
}
//Insertion in beginning
}