subject

C++ Sometimes a program requires two stacks containing the same type of entries. two coexisting stacks If the two stacks are stored in separate arrays, then one stack might overflow while there was considerable unused space in the other. A neat way to avoid this problem is to put all the space in one array and let one stack grow from one end of the array and the other stack start at the other end and grow in the opposite direction, i. e.,toward the first stack. In this way, if one stack turns out to be large and the other small, then they will still both fit, and there will be no overflow until all the space is actually used. 1) Declare a new class Double_stack that includes (as private data members) the array and the two indices top_a and top_b, and write function implementations for the methods Double_stack( ), push_a( ), push_b(), pop_a( ), pop_b( ), top_a( ), top_b( ), empty_a( ), empty_b( ), and full( ) to handle the two stacks within one Double_stack. 2) Document your code with comments, and write the test program to test every member functions implemented in the class. 3) Write a summary report that includes your displayed test results.
const int maxstack = 20;//small value for testing
typedef int Stack_entry;
class Double_stack
{
public:
Double_stack( );
bool empty_a( )const;
bool empty_b( )const;
bool full( )const ;//Same method checks both stacks for fullness.
void pop_a( );
void pop_b( );
Stack_entry top_a( )const;
Stack_entry top_b( )const;
void push_a(const Stack_entry&item);
void push_b(const Stack_entry&item);
private:
int top_a;//index of top of stacka; βˆ’1 if empty
int top_b;//index of top of stackb; maxstack if empty
Stack_entry entry[maxstack];
};

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 06:30
Who can provide you with a new password when you have forgotten your old one? your provide you with a new password in case you forget your old one.
Answers: 3
question
Computers and Technology, 23.06.2019 17:30
What are the most commonly found items in the trash according to the municipal solid waste report?
Answers: 1
question
Computers and Technology, 24.06.2019 10:10
Which view in a presentation program displays a split window showing the slide in the upper half and a blank space in the lower half?
Answers: 1
question
Computers and Technology, 24.06.2019 10:30
This device directs network traffic. bridge hub nic repeater router switch
Answers: 3
You know the right answer?
C++ Sometimes a program requires two stacks containing the same type of entries. two coexisting sta...
Questions
question
English, 24.03.2021 08:40
question
Mathematics, 24.03.2021 08:40
question
Mathematics, 24.03.2021 08:40
question
Arts, 24.03.2021 08:40
question
Mathematics, 24.03.2021 08:40
Questions on the website: 13722363