-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackll.c
More file actions
79 lines (73 loc) · 1.13 KB
/
stackll.c
File metadata and controls
79 lines (73 loc) · 1.13 KB
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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct Node
{
int info;
struct Node *next;
}*ptr,*first,*prev_ptr,*last;
void display(struct Node *ptr)
{
while(ptr!=NULL)
{
printf("%d ",ptr->info);
ptr=ptr->next;
}
}
void create(int h)
{
ptr=(struct Node*)malloc(sizeof(struct Node));
ptr->info=h;
ptr->next=NULL;
if(first==NULL)
{
last=ptr;
first=ptr;
}
else
{
last->next=ptr;
last=ptr;
}
}
void delete(struct Node *prev_ptr)
{
ptr=prev_ptr->next;
while(ptr->next!=NULL)
{
prev_ptr=ptr;
ptr=ptr->next;
}
prev_ptr->next=NULL;
free(ptr);
}
int main()
{
int x;
char ch[10];
first=NULL;
last=NULL;
do
{
printf("\npush the element in stack:\n");
scanf("%d",&x);
create(x);
printf("stack after pushing is:\n");
display(first);
printf("\ndo you want to push further elements?\n");
scanf("%s",ch);
}
while(strcmp(ch,"yes")==0);
printf("\ndo you want to pop an element?\n");
scanf("%s",ch);
while(strcmp(ch,"yes")==0)
{
delete(first);
display(first);
printf("\ndo you want to pop further?\n");
scanf("%s",ch);
}
printf("stack after pushing and popping is:\n");
display(first);
return 0;
}