Sunday, October 2, 2011

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

1 comment:

  1. can u give me a program for linear search ?
    coz i need it for a mini project. can u plzz guide me in it?

    ReplyDelete