-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcll-traversing.c
53 lines (51 loc) · 995 Bytes
/
cll-traversing.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
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node * next;
}*head,*new,*p;
void create(int n);
void displaylist();
int main()
{
printf("enter total no of nodes");
int n;
scanf("%d",&n);
create(n);
printf("data in the list\n");
displaylist();
}
void create(int n)
{
int val ,i;
head=(struct node*)malloc(sizeof(struct node));
printf("enter value of node1");
scanf("%d",&val);
head->data=val;
head->next=NULL;
p=head;
for(i=2;i<=n;i++)
{
new=(struct node *)malloc(sizeof(struct node));
printf("enter data of node %d",i);
scanf("%d",&val);
new->data=val;
new->next=NULL;
p->next=new;
p=p->next;
// p=new;
p->next=head;
}
printf("circular linked list created successfully\n");
}
void displaylist()
{
p=head;
printf("data in list");
do{
printf("%d->",p->data);
p=p->next;
}
while(p!=head);
}