0% found this document useful (0 votes)
6 views

Stack C

stack program

Uploaded by

nayiid556
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Stack C

stack program

Uploaded by

nayiid556
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

PROGRAM 4a

Program Name-Array implementa on of Stack Name-Rishabh Pandey

Domain-Stack Roll No-2300320130195

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(){

prin ("Enter element");

scanf("%d",&item);

if(!isfull())

top=top+1;

s[top]=item;

else

prin ("stack overflow");

void pop(){

if(!isempty()){

prin ("Element deleated:%d",s[top]);

top=top-1;
PROGRAM 4a
Program Name-Array implementa on of Stack Name-Rishabh Pandey

Domain-Stack Roll No-2300320130195

Code:

else{

prin ("Stack is empty");

} }

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");

prin ("Enter your choice");

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

Domain-Stack Roll No-2300320130195

Code:

OUTPUT:-
1.push

2.pop

3.display

4.exitEnter your choice1

Enter element12

1.push

2.pop

3.display

4.exitEnter your choice1

Enter element23

1.push

2.pop

3.display

4.exitEnter your choice1

Enter element44

1.push

2.pop

3.display

4.exitEnter your choice3

44

23

12

1.push

2.pop

3.display

4.exitEnter your choice4

PS C:\Users\RISHABH\c programs>

You might also like