-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathlinkedlist2.c
135 lines (118 loc) · 2.07 KB
/
linkedlist2.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
struct list
{
struct list *ptr;
int data;
};
struct list *first=NULL;
void create()
{
struct list *node=NULL;
char ch='f';
int i=1;
while(ch=='f' || ch=='F')
{
if(i==1)
{
node=(struct list *)malloc(sizeof(struct list));
node->ptr=NULL;
printf("\n enter the value");
scanf("%d",&node->data);
node->ptr=NULL;
first=node;
i=i+1;
}
else
{
node->ptr=(struct list *)malloc(sizeof(struct list));
node=node->ptr;
printf("\n enter the value");
fflush(stdin);
scanf("%d",&node->data);
node->ptr=NULL;
}
printf("\n press f to continue");
fflush(stdin);
scanf("%c",&ch);
}
}
void insert_beg()
{
struct list *node=(struct list *)malloc(sizeof(struct list));
node=node->ptr;
printf("\nEnter the value to insert in beginning");
scanf("%d",&node->data);
node->ptr=first;
first=node;
}
void insert_end()
{
}
void insert_pos()
{
}
void delete_beg()
{
}
void delete_end()
{
}
void delete_pos()
{
}
void display()
{
struct list *node=first;
while(node!=NULL)
{
printf("->%d",node->data);
node=node->ptr;
}
}
int main()
{
int ch;
create();
while(1)
{
printf("\nenter 1 for insert at beginning");
printf("\nenter 2 for insert at end");
printf("\nenter 3 for insert at any position");
printf("\nenter 4 for delete at beginning");
printf("\nenter 5 for delete at end");
printf("\nenter 6 for delete at any position");
printf("\nenter 7 for display");
printf("\nenter 8 for exit");
printf("\nenter your menu choice");
fflush(stdin);
scanf("%d",&ch);
switch(ch)
{
case 1:
insert_beg();
break;
case 2:
insert_end();
break;
case 3:
insert_pos();
break;
case 4:
delete_beg();
break;
case 5:
delete_end();
break;
case 6:
delete_pos();
break;
case 7:
display();
break;
case 8:
return 0;
}
}
}