DSA - Exp1 - Vu4f2021081 - Sushant Patil
DSA - Exp1 - Vu4f2021081 - Sushant Patil
Id’No.:-vu4f2021120 batch:-D
Div:-A/I.t,. Subject:-DSA
Experiment No.1
Stack Implementation
code
#include<stdio.h>
#include<stdlib.h>
#define MAX 10
top = -1;
peek(); int
isEmpty(); int
isFull(); void
display();
main()
int choice,item;
while(1)
{
printf("1.Push\n");
printf("2.Pop\n");
printf("5.Quit\n"); printf("Enter
switch(choice)
case 1 :
scanf("%d",&item);
push(item);
break;
break;
case 3:
break;
case 4:
display();
break;
case 5:
exit(1);
default:
printf("Wrong choice\n");
}/*End of switch*/
getch() ;
}/*End of while*/
}/*End of main()*/
if( isFull() )
printf("Stack Overflow\n");
return;
top = top+1;
stack_arr[top] = item;
}/*End of push()*/
int pop()
int item;
if( isEmpty() )
printf("Stack Underflow\n");
exit(1);
}
item = stack_arr[top];
}/*End of pop()*/
int peek()
if( isEmpty() )
printf("Stack Underflow\n");
exit(1);
return stack_arr[top];
}/*End of peek()*/
int isEmpty()
if( top == -1 )
return 1;
else return 0;
}/*End of isEmpty*/
int isFull()
return 1;
else return 0;
}/*End of isFull*/
void display()
int i;
if( isEmpty() )
printf("Stack is empty\n");
return;
for(i=top;i>=0;i--)
}/*End of display()*/