Professional Documents
Culture Documents
Assignment 5
Assignment 5
PRN- 21510102
BATCH- S6
BRANCH- SY CSE BTECH
ASSIGNMENT-5
Implmentation of Two Stacks :
Code :
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define s string
/*------------------------------------------*/
/* Author : Maria Shaikh */
/* Walchand College of Engineering, Sangli*/
/*--------------------------------------------*/
class TwoStack{
public:
int *arr;
int top1;
int top2;
int size;
TwoStack(int s){
this->size=s;
top1=-1;
top2=s;
arr=new int[s];
}
void popOne(){
if(top1== -1){
cout<<"Stack one is empty";
}
else{
top1--;
}
}
void popTwo(){
if(top2==size){
cout<<"Stack Two is Empty";
}
else{
top2++;
}
}
int peekOne(){
if(top1== -1){
cout<<"stack One is empty"<<endl;
}
else{
return arr[top1];
}
}
int peekTWo(){
if(top2==size){
cout<<"Stack two is Empty"<<endl;
}
else{
return arr[top2];
}
}
bool oneEmpty(){
if(top1== -1) return true;
else return false;
}
bool TWoEmpty(){
if(top2==size) return true;
else return false;
}
};
int main(){
TwoStack st(6);
//Pusshing in 1st stack
st.PushOne(1);
st.PushOne(2);
//pusihing in 2nd stack
st.PushTwo(3);
st.PushTwo(4);
cout<<"Top one :"<<st.peekOne()<<endl;
cout<<"Top Two :"<<st.peekTWo()<<endl;
st.popOne();
st.popTwo();
cout<<"Top one :"<<st.peekOne()<<endl;
cout<<"Top Two :"<<st.peekTWo()<<endl;
//Empty or not
st.popOne();
st.popTwo();
st.popOne();
st.popTwo();
return 0;
}
OutPut :