0% found this document useful (0 votes)
2 views4 pages

sstack_swap

Swap function

Uploaded by

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

sstack_swap

Swap function

Uploaded by

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

#include <iostream>

using namespace std;

class SStack{

int arr[10];

int arr2[10];

int top;

int top2;

public:

SStack(){

top=-1;

top2=-1;

void push(int a){

if(top>=10){

cout<<"Stack is overflow"<<endl;

else{

top++;

arr[top]=a;

int pop(){

if(top==-1){

cout<<"Stack is underflow"<<endl;

else{

int num=arr[top];

arr[top]=0;

top--;
return num;

void display(){

if(top==-1){

cout<<"Stack is underflow"<<endl;

else{

cout<<""<<endl;

for(int a=0;a<=top;a++){

cout<<arr[a]<<endl;

void display2(){

if(top2==-1){

cout<<"Stack is underflow"<<endl;

else{

cout<<"Array 2"<<endl;

cout<<""<<endl;

for(int a=0;a<=top2;a++){

cout<<arr2[a]<<endl;

void swap(){

if(top==-1){

cout<<"Stack is underflow"<<endl;
}

else{

while(top!=-1){

top2++;

arr2[top2]=arr[top];

top--;

};

int main(int argc, char** argv) {

SStack s1,s2;

int ch;

while(true){

cout<<"Menu"<<endl;

cout<<"1. push"<<endl;

cout<<"2. display"<<endl;

cout<<"3. pop"<<endl;

cout<<"4. swap"<<endl;

cout<<"5. display of arr2"<<endl;

cout<<"6. exit"<<endl;

cout<<"Enter your choice"<<endl;

cin>>ch;

switch(ch){

case 1:

s1.push(10);

break;

case 2:
s1.display();

break;

case 3:

s1.pop();

break;

case 4:

s1.swap();

break;

case 5:

s1.display2();

break;

case 6:

return 0;

break;

default:

cout<<"Invalid input"<<endl;

You might also like