0% found this document useful (0 votes)
2 views

p9(Stack Using Array)

Uploaded by

abaiju696
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

p9(Stack Using Array)

Uploaded by

abaiju696
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

/*STACK USING ARRAY*/

#include<stdio.h>

#include<stdlib.h>

#define MAXSTK 5

int TOP = -1;

int s[MAXSTK];

void push();

void pop();

void display();

int main()

int choice;

while(1)

printf("1. Push\n");

printf("2.Pop\n");

printf("3.Display\n");

printf("4.Quit\n");

printf("Enter your choice: ");

scanf("%d", &choice);

switch(choice)

case 1:

push();

break;

case 2:

pop();

break;

case 3:

display();
break;

case 4:

exit(0);

default: printf("Wrong choice\n");

} /*End of switch*/

/* Function to push an push()*/

void push()

int item;

if (TOP== (MAXSTK-1))

printf("Stack Overflow\n");

else

/* 'item' is the item to be pushed */

printf("Enter the item to be pushed in stack : ");

scanf("%d", &item);

TOP=TOP+1;

s[TOP] = item;

/* Function to pop an item from the stack */

void pop()

if (TOP == -1)

printf("Stack Underflow\n");

else

{
printf("Popped element is: %d\n",s[TOP]);

TOP=TOP-1;

void display()

int i;
if(TOP == -1)
printf("Stack Underflow\n");
else
{

printf("Stack elements : \n");


for(i= TOP; i >=0; i--)
printf("%d\n", s[i] );
}
}
OUTPUT:

You might also like