-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcll-at-beg.c
70 lines (68 loc) · 1.27 KB
/
cll-at-beg.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
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node * next;
}*head,*new,*p;
void create(int n);
void displaylist();
void insertatbig(int d);
void displaylist();
int main()
{
printf("enter total no of nodes");
int n,d;
scanf("%d",&n);
create(n);
scanf("%d",&d);
insertatbig( d);
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 insertatbig(int d)
{
new=(struct node *)malloc(sizeof(struct node));
new->data=d;
new->next=head;
p=head;
while(p->next!=head)
{
p=p->next;
}
p->next=new;
head=new;
}
void displaylist()
{
p=head;
printf("data in list");
do{
printf("%d->",p->data);
p=p->next;
}
while(p!=head);
}