0% found this document useful (0 votes)
6 views3 pages

4

This document contains a C program that implements a stack data structure with basic operations such as push, pop, and display. The program allows users to interactively perform these operations through a menu-driven interface. It includes error handling for stack overflow and underflow conditions.

Uploaded by

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

4

This document contains a C program that implements a stack data structure with basic operations such as push, pop, and display. The program allows users to interactively perform these operations through a menu-driven interface. It includes error handling for stack overflow and underflow conditions.

Uploaded by

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

#include <stdio.

h>
#include <stdlib.h>
#define SIZE 4

int top = -1, inp_array[SIZE];

void push();

void pop();

void display();
int main()
{

int choice;
while (1)

printf("\nPerform operations on the stack:");

printf("\n1.Push the element\n2.Pop the element\n3.Show\n4.End");

printf("\n\nEnter the choice: ");

scanf("%d", &choice);

switch (choice)

case 1:

push();

break;

case 2:

pop();

break;

case 3:

show();

break;

case 4:

exit(0);

default:
printf("\nInvalid choice!!");

void push()

int x;

if (top == SIZE - 1)

printf("\nOverflow!!");

else

printf("\nEnter the element to be added onto the stack: ");

scanf("%d", &x);

top = top + 1;

inp_array[top] = x;

void pop()

if (top == -1)

printf("\nUnderflow!!");

else

{
printf("\nPopped element: %d", inp_array[top]);

top = top - 1;

void display()

if (top == -1)

printf("\nUnderflow!!");

else

printf("\nElements present in the stack: \n");

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

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

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