Homework Help Question & Answers

C++ myStack.lh stackADT.h Instructions main.cpp 1 #include«iostream» 2 #include<stdlib.h> 3 #include«conio.h> 4 #include«ostream» 5 using namespace std; 6 const int SIZE-5; //Stack size 7 //...

C++

myStack.lh stackADT.h Instructions main.cpp 1 #include«iostream» 2 #include<stdlib.h> 3 #include«conio.h> 4 #include«ostream»

myStack.lh stackADT.h Instructions main.cpp 1 #include«iostream» 2 #include 3 #include«conio.h> 4 #include«ostream» 5 using namespace std; 6 const int SIZE-5; //Stack size 7 //class declaration 8 class stack Instructions Two stacks of the same type are the same if they have the same number of elements and their elements at the corresponding positions are the same Overload the relational operatorfor the class stackType that returns true if two stacks of the same type are the same; it returns false otherwise. 10 int items SIZE 11 int top; 12 int full(); 13 int empty(); 14 public: 15 stack() 16 17 top -1; 18 19 stack operator--(int); 20 friend stack operator (stack s1,int elem); 21 bool operator(stack &); 22 friend ostream &operator
0 0
Next > < Previous
ReportAnswer #1

#include<bits/stdc++.h>
using namespace std;
#define limit 1000
class Stack
{
int top;
public:
int stack[limit];
Stack()
{
top=0;
}
void push(int x) //push operation
{
if(top >= (limit))
{
cout << "Stack Overflow";
}
else
{
stack[top] = x;
top++;
}
}
int pop() // pop opertaion
{
if(top<=0)
{
cout<<"Stack Underflow";
}else
{
int r;
top--;
r=stack[top];
return r;
}
}
bool operator == (Stack &s2) //overload == operator
{
if(top!=s2.top) // if size not equal than stack are not same
{
return false;
}else
{
for(int i=0;i<top;i++)
{
if(stack[i]!=s2.stack[i]) /* if at any index element not same stack are not equal*/
{
return false;
}
}
return true;
}

}
};
int main()
{
Stack s;
s.push(10);
s.push(20);
s.push(30);
Stack s1;
s1.push(10);
s1.push(20);
s1.push(30);
if(s==s1)
{
cout<<"Stack are same";
}else
{
cout<<"Stack are not same";
}
return 0;
}

/*

Output:-

Stack are same

*/

Add Homework Help Answer
Add Answer of:
C++ myStack.lh stackADT.h Instructions main.cpp 1 #include«iostream» 2 #include<stdlib.h> 3 #include«conio.h> 4 #include«ostream» 5 using namespace std; 6 const int SIZE-5; //Stack size 7 //...
Your Answer: Your Name: What's your source?
Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
More Homework Help Questions Additional questions in this topic.
Need Online Homework Help?
Ask a Question
Get FREE Expert Answers
WITHIN MINUTES
Related Questions