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 01:30
For a typical middle-income family, what is the estimated cost of raising a child to the age of 18? $145,500 $245,340 $304,340 $455,500
Answers: 2
question
Computers and Technology, 23.06.2019 11:50
While preforming before operation pmcs, you notice the front right tire appears slightly under-inflated. what is the proper action?
Answers: 3
question
Computers and Technology, 23.06.2019 14:00
How are stop motion special effects in animated films created
Answers: 1
question
Computers and Technology, 23.06.2019 22:30
Janice usually works on a particular workbook that contains all business related data. she decides to keep a backup of all the data in a separate workbook. she opens a new workbook to transfer the data. which option should she use to copy all the data from one workbook to another workbook?
Answers: 1
You know the right answer?
C++ Sometimes a program requires two stacks containing the same type of entries. two coexisting sta...
Questions
question
Social Studies, 18.11.2020 08:50
question
Arts, 18.11.2020 08:50
question
English, 18.11.2020 08:50
question
Mathematics, 18.11.2020 08:50
question
Mathematics, 18.11.2020 08:50
question
English, 18.11.2020 08:50
question
Physics, 18.11.2020 08:50
question
Mathematics, 18.11.2020 08:50
question
Biology, 18.11.2020 08:50
Questions on the website: 13722362