-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStack1.c
82 lines (78 loc) · 1.12 KB
/
Stack1.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
/*
* Stack1.c
*
* Created on: 20 Jul 2024
* Author: ABHISHEK
*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define STACKSIZE 100
struct stack
{
int top;
int items[STACKSIZE];
};
int empty(struct stack *ps)
{
if(ps->top==-1)
{
//return;
//printf("Stack is empty");
return 1;
}
else
{
//printf("\nStack is not empty");
return 0;
}
}
int pop(struct stack *ps)
{
if(empty(ps))
{
printf("\nStack underflow");
exit(1);
}
else
{
return ps->items[ps->top];
//return ps->top--;
}
}
void push(struct stack *ps,int x)
{
ps->items[(ps->top)]=x;
ps->top++;
return;
}
int main()
{
struct stack s;
int a=-1;
int b;
while(a==-1)
{
printf("\nEnter option\n1 Push \n2 Pop \n3 Exit");
scanf("%d",&b);
switch(b)
{
case 1:
int x;
printf("\nEnter element to store in stack :");
scanf("%d",&x);
push(&s,x);
break;
case 2:
int a1;
a1=pop(&s);
printf("\nElement poped = %d",a1);
s.top--;
break;
case 3:
exit(0);
}
}
getch();
return 0;
}