forked from harshitbansal373/hacktoberfest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stack.c
64 lines (62 loc) · 1.06 KB
/
Stack.c
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
// Implementation of Stack
// Operation : Push() and Pop()
#include <stdio.h>
#define MAX 10
int A[10];
void push(int [],int,int*);
int pop(int[],int*);
void main()
{
int top = 0,ch,num;
do
{
printf("\n enter your choices \n1.Push operation \n2.Pop operration \n3.Exit\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\n Pls enter a num to be pushed : ");
scanf("%d",&num);
push(A,num,&top);
break;
case 2:
printf("\n Pls enter a number to be pop:");
scanf("%d",num);
break;
case 3:
break;
default:
printf("\n Wrong choise !");
}
}while(ch != 3);
}
void push(int A[],int num, int* top)
{
if(*top == MAX)
{
printf("\n The stack is FULL !");
return;
}
else
{
*top = *top + 1;
A[*top] = num;
printf("\n The pushed element is %d and position is %d",num,*top);
}
}
int pop(int A[], int* top)
{
int num;
if(*top == 0)
{
printf("\n The stack is empty !");
return;
}
else
{
A[*top] = num;
printf("\n The poped element is %d and position is %d",num,*top);
*top = *top - 1;
return(num);
}
}