-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStack Using Array
66 lines (54 loc) · 988 Bytes
/
Stack Using Array
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
//Stack using Array
#include<bits/stdc++.h>
using namespace std;
struct Stack
{
int size;
int top;
int *s;
};
void create(struct Stack *st)
{
printf("Enter Size");
scanf("%d",&st->size);
st->top=-1;
st->s=(int *)malloc(st->size*sizeof(int));
}
void Display(struct Stack st)
{
for(int i=top;i>=0;i--)
printf("%d",st.s[i]);
printf("\n");
}
void push(struct Stack *st,int x)
{
if(st->top==st->size-1)
printf("Stack Overflow\n");
else
{
st->top++;
st->s[st->top]=x;
}
}
int push(struct Stack *st)
{
int x=-1;
if(st->top==-1)
printf("Stack Empty");
else
{
x=st->s[st->top];
st->top--;
}
return x;
}
int main()
{ struct Stack st;
create(&st);
push(&st,10);
push(&t,20);
push(&st,30);
Display(st);
printf("%d \n",pop(&st));
return 0;
}