-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircularLInkedList.c
76 lines (59 loc) · 1.33 KB
/
circularLInkedList.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
#include <stdio.h>
#include <stdlib.h>
struct node *head;
struct node{
int data;
struct node *next;
};
//display the values of linked-List
void display(struct node *flag){
int count = 0;
while(flag->next!=head){
printf("%d->", flag->data);
flag = flag->next;
count++;
}
printf("%d\n", flag->data);
printf("Total node is : %d.\n", count+1);
}
//add node at random place
void addItem(int val){
struct node *p = head, *newN;
newN = malloc(sizeof(struct node));
newN->data = val;
if(head==NULL){
head = newN;
newN->next = head;
return;
}
while(p->next!=head){
p = p->next;
}
newN->next = p->next;
p->next = newN;
}
//remove node from anywhere of that node
void deleteItem(int val){
struct node *temp = head, *tempO;
while(temp->next->data !=val){
temp = temp->next;
}
tempO = temp->next;
temp->next = temp->next->next;
printf("%d has been removed.\n", tempO->data);
free(tempO);
}
int main(void){
head = NULL;
addItem(1);
addItem(2);
addItem(3);
addItem(5);
addItem(6);
addItem(7);
display(head);
deleteItem(2);
deleteItem(6);
display(head);
return 0;
}