-
Notifications
You must be signed in to change notification settings - Fork 0
/
linklist1.c
112 lines (101 loc) · 1.65 KB
/
linklist1.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
#include<stdio.h>
#include<stdlib.h>
struct node
{ //structure of node
int info;
struct node *link;
};
struct node *START = NULL; //start pointer to control the link list
struct node * createnode();
void insertnode(); //insert at last
void deletenode(); //delete at first
void viewlist();
int menu();
struct node * createnode() //create node dynamically
{
struct node *n;
n = malloc(sizeof(struct node));
return(n);
}
void insertnode()
{
struct node *temp,*t;
temp = createnode();
printf("Enter the data in node \n");
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 deletenode()
{
if(START==NULL)
printf("List is empty\n");
else
{
struct node *q;
q=START;
START=START->link;
free(q);
}
}
void viewlist()
{
struct node *t;
if(START==NULL)
printf("No List is there\n");
else
{
t=START;
while(t!=NULL)
{
printf("%d",t->info);
t=t->link;
}
}
}
int menu()
{
int ch;
printf("\t\t\t 1. Insert NODE at last in LINK LIST\n");
printf("\t\t\t 2. View LIST in LINK LIST\n");
printf("\t\t\t 3. Delete NODE at first in LINK LIST\n");
printf("\t\t\t 4. Exit\n");
printf("Enter your choice\n");
scanf("%d",&ch);
return(ch);
}
int main()
{
while(1)
{
switch(menu())
{
case 1:
insertnode();
break;
case 2:
viewlist();
break;
case 3:
deletenode();
break;
case 4:
exit(0);
break;
default:
printf("\nThis choice doesn't exist.\n");
}
}
}