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

Stack 1

Vgg. Bhndsfgh

Uploaded by

gm506307
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Stack 1

Vgg. Bhndsfgh

Uploaded by

gm506307
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>
#include <stdlib.h>
// Maximum size of stack is 5(that i have taken)
#define max 5

// stack[] and top is declared and initialised


int stack[max], top = -1;
// This function is used to POP/delete item from stack
void pop()
{
int item;
if (top == -1)
{
printf("Empty Stack: Underflow condition occured");
return;
}
item = stack[top];
printf("%d is POPPED\n",item);
top--;
return;
}
// This function is used to PUSH item onto the STACK
void push(int item)
{
if (top == max - 1)
{
printf("Overflow Condition occured");
return;
}
top++;
stack[top] = item;
return;
}
// This function is used to display the ITEMS stored in STACK
void show()
{
int item, i;
if (top == -1)
{
printf("Empty Stack\n");
return;
}
for (i = 0; i <= top; i++)
{
printf("%d ->", stack[i]);
}

printf("\n");

return;
}

int main()
{
int item, ch;
// This is a menu driven Program
while (1)
{
printf("1. PUSH\n2.POP\n3.Show\n4.Quit\n");
printf("Enter your choice(1,2,3 or 4) ... ");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("Enter an item to be pushed ");
scanf("%d", &item);
push(item);
break;
case 2:
pop();
break;
case 3:
show();
break;
case 4:
exit(0);
break;
default:
printf("Invalid Input");
break;
}
}
return 0;
}

// End of the Project

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