0% found this document useful (0 votes)
4 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)
4 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy