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

STACC ATACC 2.0

This document contains a C++ implementation of a stack data structure with basic operations such as push, pop, and print. The program allows users to interactively push and pop elements from the stack, while handling overflow and underflow conditions. The main function provides a simple user interface for performing these operations up to a maximum of 10 elements.

Uploaded by

Sajid Ali
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)
4 views3 pages

STACC ATACC 2.0

This document contains a C++ implementation of a stack data structure with basic operations such as push, pop, and print. The program allows users to interactively push and pop elements from the stack, while handling overflow and underflow conditions. The main function provides a simple user interface for performing these operations up to a maximum of 10 elements.

Uploaded by

Sajid Ali
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<iostream>

using namespace std;

int top = -1;


int n = 10;
int arr[100];

void push(int x)
{
if (top >= n - 1)
{
cout << "STACK OVERFLOW" << endl;
}
else
{
top++;
arr[top] = x;

}
void pop()

{
if (top <= -1)
{
cout << "STACK UNDERFLOW" << endl;
}
else
{
top--;
cout << arr[top] << endl;

}
void print()
{
if (top >= 0)
{

cout << "THE STACK ELEMENTS ARE :" << endl;


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

cout << arr[i] << endl;

}
}
else
{
cout << "STACK IS EMPTY" << endl;

int main()
{
char A;
int B, C;
int a = 0;

while (a < 2) {
cout << "IF YOU WANT TO PUSH ELEMENTS INTO THE STACK THEN SELECT
'A':" << endl;
cout << "IF YOU WANT TO Pop ELEMENTS out of THE STACK THEN SELECT
'B':" << endl;

cin >> A;
switch (A)
{
case 'A':
cout << "how many times do you want to insert elements into
the stack?(max 10)" << endl;
cin >> B;
while (B > 0)
{
cout << "enter the elements:" << endl;
cin >> C;
push(C);
B--;
}
break;

case 'B':
cout << "how many times do you want to pop elements out of
the stack?(max 10)" << endl;
cin >> B;
cout << "the following elements are poped out:" << endl;
while (B > 0)
{
pop();
B--;
}
break;

}
a++;
}
print();

return 0;
}

You might also like