-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStack_Array.c
More file actions
80 lines (66 loc) · 1019 Bytes
/
Copy pathStack_Array.c
File metadata and controls
80 lines (66 loc) · 1019 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
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
#include <stdio.h>
#define max 10
void push(int arr[],int val);
void pop(int arr[]);
void display(int arr[]);
int arr[max];
int top=-1;
int main()
{
int option,val;
do
{
printf("\nPress 1 For Push: ");
printf("\nPress 2 For pop: ");
printf("\nPress 3 For display: ");
printf("\nPress 4 for Quit: ");
scanf("\n%d",&option);
switch(option)
{
case 1: printf("\nEnter The value: ");
scanf("\n%d",&val);
push(arr,val);
break;
case 2: pop(arr);
break;
case 3: display(arr);
break;
}
}while(option!=4);
return 0;
}
//pushing The Elements into The stack
void push(int arr[],int val)
{
if(top==max-1)
printf("\nStack is Full ");
else
{
top++;
arr[top]=val;
}
}
//pop the elements from Stack
void pop(int arr[])
{
if(top==-1)
printf("\nStack is Underflow");
else
{
arr[top]=NULL;
top--;
}
}
//display the Stack
void display(int arr[])
{
if(top==-1)
printf("\nStack is Empty ");
else
{
for (int i = top; i >=0 ; i--)
{
printf("\n%d",arr[i]);
}
}
}