-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathsingly-linkedlist
86 lines (80 loc) · 1.36 KB
/
singly-linkedlist
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
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int info;
struct node *link;
};
struct node* start=NULL;
struct node* createnode()
{
struct node* temp;
temp=(struct node*)malloc(sizeof(struct node));
return(temp);
}
void insertend()
{
struct node* tmp,*t;
tmp=createnode();
printf("Enter the node\n");
scanf("%d",&tmp->info);
if(start==NULL)
start=tmp;
else
t=start;
while(t->link!=NULL)
t=t->link;
t->link=tmp;
}
void deletefirst()
{
struct node* r;
if(start==NULL)
printf("List is empty");
else
r=start;
start=start->link;
free(r);
}
void display()
{
struct node* t;
if(start==NULL)
{
printf("List is empty");
}
else
{
t=start;
while(t!=NULL)
{
printf("%d",t->info);
t=t->link;
}
}
}
int main()
{
int n;
printf("Choose \n 1.INSERT \n 2.DELETE \n 3.DISPLAY \n 4.EXIT \n");
scanf("%d",&n);
while(1)
{
switch(n)
{
case 1:insertend();
break;
case 2:deletefirst();
break;
case 3:display();
break;
case 4:exit(0);
break;
default:printf("Choose correct option\n");
break;
}
getch();
}
return 0;
}