-
Notifications
You must be signed in to change notification settings - Fork 1
/
linked list.cpp
78 lines (76 loc) · 1.05 KB
/
linked list.cpp
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
#include<stdio.h>
#include<conio.h>
using namespace std;
struct node{
int info;
struct node *link;
};
struct node*START=NULL;
struct node * createnode(){
struct node *n;
n=(struct node*)malloc(sizeof(struct node));
return n;
}
void insertnode(){
struct node*temp,*t;
temp=createnode();
printf("enter the data");
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{
struct node* r;
if(START==NULL)
{
printf("the list is empty");
}
else{
r=START;
START=START->link;
free(r);}
}
void viewlist(){
struct node*t;
if(START==NULL){
printf("the list is empty");
}
else{
t=START;
while(t!=NULL){
cout<<t->info;
t=t->link;
}
}
}
void main(){
int ch;
printf("1.add value\n");
printf("2.delete value\n");
printf("3.view value");
scanf("%d",&ch);
while(1){
switch(ch){
case 1:
insertnode();
break;
case 2:
deletenode();
break;
case 3:
viewlist();
break;
default:
cout<<"there is no other choice";
}
}
}