forked from anoop-singh-dev/data-structures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple linkedlist.c
94 lines (94 loc) · 1.56 KB
/
simple linkedlist.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
#include<stdio.h>
#include<stdlib.h>
struct node
{ int info;
struct node *link;
};
struct node *start = NULL;
struct node *create()
{
struct node *n;
n = (struct node*)malloc(sizeof(struct node));
return (n);
};
void insert()
{
struct node *temp,*t;
temp = create();
printf("enter your infomations");
scanf("%d",&temp->info);
temp->link=NULL;
if(start==NULL)
{
start = temp;
}
else
{
t = start;
while(t->link!=NULL)
{
t=t->link;
}
t->link = temp;
}
}
void del()
{
struct node *r;
if(start==NULL)
{
printf("list is empty");
}
else
{
r = start;
start = start->link;
free(r);
}
}
void viewlist()
{
struct node *a;
if(start == NULL)
{
printf("list is empty");
}
else
{
a = start;
while(a!=NULL)
{
printf("%d",a->info);
a = a->link;
}
}
}
int menu()
{
int ch;
printf("\n 1.add value of list");
printf("\n 2.delete first value");
printf("\n 3.view list");
printf("\n 4. exit");
printf("\n enter your choice");
scanf("%d",&ch);
return(ch);
}
void main()
{
while(1)
{
switch(menu())
{
case 1:insert();
break;
case 2:del();
break;
case 3:viewlist();
break;
case 4:exit(0);
default:
printf("invalid choice");
}
}
}