#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);
}
}
This blog will cover all important aspects of 'C' 'C++', 'Data Structures in C' and other Technical stuffs. In this blog you will find good C Interview Questions Answers. I will be posting both multiple choice and subjective type C interview questions and answers. Tutorials will be posted from time to time that will focus on problem solving.
Sunday, October 2, 2011
Data Structure C program Stack using Array Dev c++
Labels:
data structures
Subscribe to:
Post Comments (Atom)
can u give me a program for linear search ?
ReplyDeletecoz i need it for a mini project. can u plzz guide me in it?