c-record - 9) stack

 #include<stdio.h>

#include<conio.h>

#define SIZE 3

void push();

void pop();

void peek();

void display();

int stack[SIZE],top=-1,ele;

void main()

{

int ch;

clrscr();

printf("\nMenu\n1.Push\n2.Pop\n3.Peek\n4.Display\n5.Exit\n");

while(1)

{

printf("\nEnter your choose Operator : ");

scanf("%d",&ch);

switch(ch)

{

case 1 :push();

break;

case 2 :pop();

break;

case 3 :peek();

break;

case 4 :display();

break;

default:exit();

}

}

getch();

}

void push()

{

if(top==SIZE-1)

printf("\nStack is full");

else

{

top++;

printf("\nEnter the element to be inserted into the stack : ");

scanf("%d",&ele);

stack[top]=ele;

}

}

void pop()

{

if(top==-1)

printf("\nStack is empty");

else

{

ele=stack[top];

printf("\nThe deleted element from the stack : %d ",ele);

top--;

}

}

void peek()

{

if(top==-1)

printf("\nStack is empty");

else

{

ele=stack[top];

printf("\nThe top most element of the stack : %d ",ele);


}

}

void display()

{

int i;

if(top==-1)

printf("\nStack is empty");

else

{

printf("\nThe element of the stack :\n");

for(i=top;i>=0;i--)

printf("%d\n",stack[i]);

}

}


note:- display the four image outputs continue write single output

1) output:-

alt  +f9   ------   run and

ctrl+f9   ------  compile





























Comments

Popular posts from this blog

digital marketing ppt-u1

SOFTWARE

cn lab

Computer Operations and Performing - D L Unit-1-1

DS-Record-mca-04) write a program for evaluating a given postfix expression using stack.

DBMS Degree Lab Records

Unit 2: Foundations of Ownership, Security Related Concepts in Blockchain

Unit-1 Foundations of Software Systems and Blockchain

Access the Internet to Browse Infromation & E-Mail Operation- D L Unit-2-1

6)what are the various service of internet and protocols ICT-unit-1