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

Stack Operations: Push, Pop, Display

The document provides a C++ implementation of a stack data structure with operations for pushing, popping, and displaying elements. It includes a menu-driven interface that allows users to interact with the stack by entering their choices. The code handles stack overflow and underflow conditions appropriately.

Uploaded by

sk.00sardah00
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)
12 views3 pages

Stack Operations: Push, Pop, Display

The document provides a C++ implementation of a stack data structure with operations for pushing, popping, and displaying elements. It includes a menu-driven interface that allows users to interact with the stack by entering their choices. The code handles stack overflow and underflow conditions appropriately.

Uploaded by

sk.00sardah00
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

1. Stack Operation (Push, Pop).

Code:
#include <iostream>

using namespace std;

int stack[100];

int n, i, top, x;

void push();

void pop();

void display();

int main()

int ch;

cout << "Enter the number of elements in the stack : ";

cin >> n;

i = 1;

top = -1;

while (i)

cout << "\[Link]\[Link]\[Link]\[Link]\n";

cout << "Enter your choice (1-4)<<endl: ";

cin >> ch;

switch (ch)

case 1:

push();

break;

case 2:

pop();

break;

case 3:

display();

break;
case 4:

i = 0;

break;

default:

cout << "Wrong Choice!!!!" << endl;

break;

return 0;

void push()

if (top >= n - 1)

cout << "STACK IS OVERFLOW" << endl;

else

cout << "Enter the value to be added : ";

cin >> x;

top = top + 1;

stack[top] = x;

void pop()

if (top <= -1)

cout << "STACK IS UNDERFLOW" << endl;

else
{

cout << "Value : " << stack[top] << " GOT deleted." << endl;

top--;

void display()

if (top >= 0)

cout << "Elements in the stack are : ";

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

cout << stack[i] << " ";

cout << "\n";

else

cout << "STACK IS EMPTY." << endl;

You might also like