-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ins_pos_CLL.c
98 lines (98 loc) · 1.47 KB
/
Ins_pos_CLL.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int info;
struct node* next;
};
typedef struct node* nodep;
nodep start=NULL;
void ins_pos();
nodep create();
void createlist();
void display();
int main()
{
createlist();
ins_pos();
display();
}
void createlist()
{
nodep t,t1;
char ch;
printf("Creation of list\n");
do{
t=create();
if(start==NULL)
start=t;
else
t1->next=t;
t1=t;
printf("Do you want add more(y/Y)\n");
scanf(" %c",&ch);
}while(ch=='y' || ch=='Y');
t->next=start;
}
nodep create()
{
nodep t;
t=(nodep)malloc(sizeof(struct node));
t->next=t;
printf("Enter Data\n");
scanf("%d",&t->info);
return t;
}
void ins_pos()
{
int pos,count;
nodep temp,temp1;
temp=create();
printf("Enter position\n");
scanf("%d",&pos);
temp1=start;
if(pos==1)
{
while(temp1->next!=start)
{
temp1=temp1->next;
}
temp1->next=temp;
temp->next=start;
start=temp;
}
else if(pos>1)
{
count=2;
while(temp1->next!=start && count<pos)
{
temp1=temp1->next;
count++;
}
if(pos==count)
{
temp->next=temp1->next;
temp1->next=temp;
}
else
printf("position is greater than size of list\n");
}
else
printf("position is negative\n");
}
void display()
{
nodep t;
t=start;
printf("Circular Sll\n");
if(t==NULL)
{
printf("List is empty\n");
return;
}
do{
printf("%d\t",t->info);
t=t->next;
}while(t!=start);
}