Professional Documents
Culture Documents
class Stack {
private:
int top;
int* arr_stack;
public:
int size;
Stack(){
cin>>size;
top = -1;
if(!isFull()){
arr_stack[++top] = value;
}else{
cout<<"Stack is Full"<<endl;
}
void pop(){
if(!isEmpty()){
}else{
cout<<"Stack is Empty"<<endl;
void peek(){
if(!isEmpty()){
}else{
cout<<"Stack is Empty"<<endl;
bool isFull(){
bool isEmpty(){
};
int main() {
Stack obj;
int option = 1;
while(option != 0){
cout<<"Choose an option"<<endl <<"1 to push"<<endl <<"2 to pop"<<endl <<"3 to peek"<<endl;
cin>>option;
if(option==1){
int value;
cin>>value;
obj.push(value);
else if(option==2){
obj.pop();
else if(option==3){
obj.peek();
else{
option = 0;
return 0;
}
Print Reverse String using Stack
class Stack {
private:
int top1;
int top2;
int* arr_stack;
public:
int size1;
int size2;
Stack() {
top1 = -1;
top2 = size1-1;
if (!isFull1()) {
arr_stack[++top1] = value;
}
else {
if (!isFull2()) {
arr_stack[++top2] = value;
else {
void pop1() {
if (!isEmpty1()) {
else {
void pop2() {
if (!isEmpty2()) {
else {
void peek1() {
if (!isEmpty1()) {
else {
void peek2() {
if (!isEmpty2()) {
else {
bool isFull1() {
bool isEmpty1() {
bool isFull2() {
bool isEmpty2() {
};
int main() {
int option = 1;
Stack obj;
while (option != 0) {
int value;
cout << "Select an option\nPress 1 to push in Array 1\nPress 2 to push in Array 2\nPress 3 to pop in
Array 1\nPress 4 to pop in Array 2\nPress 5 to peek in Array 1\nPress 6 to peek in Array 2\nPress 0 to
exit" << endl;
if (option == 1) {
obj.push1(value);
else if (option == 2) {
obj.push2(value);
else if (option == 3) {
obj.pop1();
else if (option == 4) {
obj.pop2();
else if (option == 5) {
obj.peek1();
else if (option == 6) {
obj.peek2();
return 0;