-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedlist.cpp
More file actions
67 lines (67 loc) · 988 Bytes
/
linkedlist.cpp
File metadata and controls
67 lines (67 loc) · 988 Bytes
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
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
typedef struct node
{
int data;
struct node *next;
}node;
node* createnode(int d)
{
node *nd;
nd=(node*)malloc(sizeof(node));
nd->data=d;
nd->next=NULL;
return nd;
}
node* createlist()
{
int data;char ans;
node *first,*last,*nd;
first=NULL;
while(1)
{
printf("enter data:-");
scanf("%d",&data);
nd= createnode(data);
if(first==NULL)
first=nd;
else
last->next=nd;
last=nd;
printf("do you want to continue(Y\N)?");
fflush(stdin);
scanf("%c",&ans);
if(ans!='y' && ans!='Y')
break;
}
return first;
}
void printlist(node *first)
{
node *t=first;
while(t!=NULL)
{
printf("%d\t",t->data);
t=t->next;
}
}
int main()
{
int c; node *start;
start=NULL;
while(1)
{
printf("1.create\n2.print\n3.exit\n");
printf("enter choice:-");
scanf("%d",&c);
switch(c)
{
case 1: start=createlist();
break;
case 2: printlist(start);
break;
case 3: exit(1);
}
}
}