stack
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define size 5
int stk[size], top = -1;
void push();
void pop();
void peep();
void disp();
void main()
{
int ch;
clrscr();
do
{
clrscr();
cout << "\n 1.push";
cout << "\n 2.pop";
cout << "\n 3.peep";
cout << "\n 4.disp";
cout << "\n 5.exit";
cout << "\nEnter your choice : ";
cin >> ch;
switch(ch)
{
case 1: push();
break;
case 2: pop();
break;
case 3: peep();
break;
case 4: disp();
break;
case 5: exit(0);
break;
default : cout << "Enter proper choice..";
}
getch();
}
while(ch != 5);
getch();
}
void push()
{
int no;
if(top >= size-1)
{
cout << "stack is full";
}
else
{
cout << "Enter any Number : ";
cin >> no;
top ++;
stk[top] = no;
}
}
void pop()
{
if( top == -1)
{
cout << "\n\t Stack is empty...";
}
else
{
cout << "Deleted number is " << stk[top];
top --;
}
}
void peep()
{
int no;
cout << "Enter searching number : ";
cin >> no;
int i;
for (i = top; i >= 0; i--)
{
if(stk[i] == no)
{
cout << "Number is found in position " << i+1;
}
}
}
void disp()
{
int i;
for (i = top; i >= 0 ; i--)
{
cout << "\t\n" << stk[i];
}
}
Comments
Post a Comment