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

Popular posts from this blog

Quetion 6 : Consider the "in-order-issue/in-order-completion" execution sequence shown in f In Figure Decode OWE Execute 12 12 12 14 16 13 16 13 15 15 16 Write 024/06/02 11 3 4 11 12 13 13 N 15 16 a. Identify the most likely reason why I could not enter the execute fourth cycle. stage until the [2] b. Will "in-order issue/out-of-order completion" or "out-of-order issue/out-of-order completion" fix this? If so, which? Explain

20.factorial using for loop

JFrame find odd/even