Stack C
Stack C
Code:
#include<stdio.h>
#define MAXSIZE 5
int s[MAXSIZE],top=-1,item;
int isempty(){
if(top==-1)
return 1;
else
return 0;
int isfull(){
if(top==MAXSIZE-1)
return 1;
else
return 0;
void push(){
scanf("%d",&item);
if(!isfull())
top=top+1;
s[top]=item;
else
void pop(){
if(!isempty()){
top=top-1;
PROGRAM 4a
Program Name-Array implementa on of Stack Name-Rishabh Pandey
Code:
else{
} }
void display(){
for(int i=top;i>=0;i--){
prin ("\n%d",s[i]);
} }
int main()
int ch;
while(1){
prin ("\n1.push");
prin ("\n2.pop");
prin ("\n3.display");
prin ("\n4.exit");
scanf("%d",&ch);
switch(ch){
case 1:push();
break;
case 2:pop();
break;
case 3:display();
break;
case 4:return 0;
} }
return 0;
}
PROGRAM 4a
Program Name-Array implementa on of Stack Name-Rishabh Pandey
Code:
OUTPUT:-
1.push
2.pop
3.display
Enter element12
1.push
2.pop
3.display
Enter element23
1.push
2.pop
3.display
Enter element44
1.push
2.pop
3.display
44
23
12
1.push
2.pop
3.display
PS C:\Users\RISHABH\c programs>