-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack_array.c
More file actions
54 lines (51 loc) · 930 Bytes
/
Copy pathStack_array.c
File metadata and controls
54 lines (51 loc) · 930 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
#include<stdio.h>
#include<stdlib.h>
#define Max 10
struct stack
{
int arr[Max];
int top;
};
void push(struct stack *sptr; int value);
void pop(struct stack *sptr);
void display(struct stack *sptr);
void main()
{
struct stack s1;
s1.top = -1;
push(&s1,2);
push(&s1,3);
pop(&s1);
display(&s1);
}
void push(struct stack *sptr, int value)
{
if(sptr->top >= Max-1)
{
printf("stack is a overflow");
}
else{
sptr->top = sptr->top+1;
printf("Enter a value in stack");
sptr->arr[sptr->top] = value;
}
}
void pop(struct stack *sptr)
{
if(sptr->top<= -1)
{
printf("stack is underflow");
}
else
{
printf("Enter a value in stack");
sptr->top=sptr->top-1;
}
}
void display(struct stack *sptr)
{
for(int i=0; i>=sptr->top;i++)
{
printf("%d",sptr->arr[i]);
}
}