-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircular_Linked_List.c
46 lines (42 loc) · 1.02 KB
/
Circular_Linked_List.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
//______________________________________________CIRCULAR LINKED LIST________________________________________________//
#include<stdio.h>
#include<stdlib.h>
struct Node {
int data;
struct Node* next;
};
//Change in Traversal Code//
void traversal(struct Node* head){
struct Node *ptr=head;
do{
printf("Element:%d\n",ptr->data);
ptr=ptr->next;
}
while(ptr !=head);
}
int main(){
struct Node* head;
struct Node* second;
struct Node* third;
head = (struct Node*)malloc(sizeof(struct Node));
second = (struct Node*)malloc(sizeof(struct Node));
third = (struct Node*)malloc(sizeof(struct Node));
head->data = 1;
head->next = second;
second->data = 2;
second->next = third;
third->data = 3;
third->next = head;
traversal(head);
return 0;
}
/*CAN ALOSO BE DONE BY THIS/////
void traversal(struct Node* head){
struct Node *ptr=head;
printf("Element:%d\n",ptr->data);
ptr=ptr->next;
while(ptr !=head){
printf("Element:%d\n",ptr->data);
ptr=ptr->next;
}
}*/