.

Data Structure C program Stack using Array Dev c++


 #include <stdio.h>  
#include <conio.h>
#define MAX 20
int top=-1,ch;
int a[MAX];
int main(){
void menu();
void push();
void pop();
void display();
menu();
while(ch!=3){
switch(ch){
case 1:
push();
display();
break;
case 2:
pop();
display();
break;
}
menu();
}
}
void push()
{
if(top==MAX-1)
printf("Stack is full\nStack overflow\n");
else
{
printf("Enter element:");
scanf("%d",&a[++top]);
}
}
void pop()
{
if(top==-1)
printf("Stack is emplty\nSTACK UNDERFLOW\n");
else
{
top--;
printf("Deleted %d\n",a[top+1]);
}
}
void display()
{
int i=0;
printf("\nStack is :\n");
for(i=top;i>=0;i--)
printf("%d\n",a[i]);
}
void menu()
{
printf("\n1.Push\n2.Pop\n3.Exit\n");
scanf("%d",&ch);
while(ch<1 || ch>3)
{
printf("Enter valid choice 1,2 or 3\n");
scanf("%d",&ch);
}
}

{ 0 comments ... read them below or add one }

Post a Comment

Google+ Followers