-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStackSimpleInC
54 lines (50 loc) · 866 Bytes
/
StackSimpleInC
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
#include <stdio.h>
#include<string.h>
#include<ctype.h>
#define size 5
struct stack
{
int a[size];
int top;
}obj;
void push(int n)
{
if(obj.top==size-1)
printf("Stack full\n");
else
{
obj.top++;
obj.a[obj.top]=n;
printf("Pushed: %d\n",n);
}
}
int pop()
{
if(obj.top==-1){
printf("Stack is empty");
return -1;
}
else
{
int temp=obj.a[obj.top];
obj.top--;
return temp;
}
}
void init()
{
obj.top=-1;
}
int main(int argc, char **argv)
{
init();
for(int i=0; i<10; i++)
{
push(i);
}
for(int i=0; i<10; i++)
{
printf("Popped: %d\n",pop());
}
return 0;
}