forked from gunanksood/C-Codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackWithArray.c
More file actions
executable file
·66 lines (66 loc) · 1.12 KB
/
Copy pathStackWithArray.c
File metadata and controls
executable file
·66 lines (66 loc) · 1.12 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
#include<stdio.h>
#include<stdlib.h>
#define MAX 5
int TOP = -1;
void PUSH( int STACK[] , int ITEM )
{
if( TOP == MAX - 1 )
{
printf("\n STACK OVERFLOW \n");
}
else
{
TOP = TOP + 1;
STACK[TOP] = ITEM;
printf("\n [ %d ] PUSHED into STACK \n",ITEM);
}
}
int POP( int STACK[] )
{
int ITEM = -1;
if( TOP == -1 )
{
printf("\n STACK UNDERFLOW \n");
}
else
{
ITEM = STACK[TOP];
TOP = TOP - 1;
}
return ITEM;
}
int main()
{
int STACK[MAX];
int run , choice , item;
run = 1;
while( run )
{
printf("\n Press 1 For PUSH Item to STACK ");
printf("\n Press 2 For POP Item From STACK ");
printf("\n Press 3 For Exit \n");
printf("\n Enter Your Choice : ");
scanf("%d",&choice);
switch( choice )
{
case 1:
printf("\n Enter Item : ");
scanf("%d",&item);
PUSH( STACK , item );
break;
case 2:
item = POP( STACK );
if( item != -1 )
{
printf("\n [ %d ] Popped From STACK \n",item);
}
break;
case 3:
run = 0;
break;
default:
printf("\n Invalid Choice. Try Again. \n");
}
}
return 0;
}