-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstack2.c
More file actions
81 lines (72 loc) · 1.27 KB
/
Copy pathstack2.c
File metadata and controls
81 lines (72 loc) · 1.27 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
67
68
69
70
71
72
73
74
75
76
77
78
79
#include<stdio.h>
#include<stdlib.h>
#define MAX_SIZE 10
int stack[MAX_SIZE],top=-1;
int isFull(){
//returns 1 if stack is full else returns -1
return top==MAX_SIZE-1;
}
int isEmpty(){
//returns 1 if stack is empty else returns -1
return top==-1;
}
int peek(){
//return element at the top of stack
return stack[top];
}
void push(int e){
//inserts an element into stack
if(!isFull())
{
top++;
stack[top]==e;
}
else
{
printf("stack overflow");
}
}
void pop(int e){
//delete element from stack
int d;
if(!isEmpty())
{
d=stack[top];
top--;
printf("elements are deleted succesfully");
}
else{
printf("stack underflow");
}
}
int main(){
int choice,e;
do
{
printf("\t\t\t \nMENU \n 1.peek \n 2.push \n 3.pop\n 4.exit\n");
printf("enter your choice");
scanf("%d",&choice);
switch(choice){
case 1:
e=peek(stack);//call peek function
printf("\nelement at the top of stack is :%d",e);
break;
case 2:printf("enter the element to be pushed");
scanf("%d",&e);
push(e);
//call push function
break;
case 3:
pop(e);
//call pop function
break;
case 4:
exit(0);
//call exit(0) function
break;
default: printf("invalid choice");
break;
}
}while(1);
return 0;
}