![aahneise02](/avatars/18449.jpg)
aahneise02
16.07.2020 •
Computers and Technology
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];
};
Solved
Show answers
More tips
- F Food and Cooking How many stages of coffee roasting are there?...
- G Goods and services Kogda zhdatt Iphone 5? The Latest News and Rumors...
- F Family and Home Parquet or laminate, which is better?...
- L Leisure and Entertainment How to Properly Wind Fishing Line onto a Reel?...
- L Leisure and Entertainment How to Make a Paper Boat in Simple Steps...
- T Travel and tourism Maldives Adventures: What is the Best Season to Visit the Luxurious Beaches?...
- H Health and Medicine Kinesiology: What is it and How Does it Work?...
- O Other How to Choose the Best Answer to Your Question on The Grand Question ?...
- L Leisure and Entertainment History of International Women s Day: When Did the Celebration of March 8th Begin?...
- S Style and Beauty Intimate Haircut: The Reasons, Popularity, and Risks...
Answers on questions: Computers and Technology
- C Computers and Technology Project: Using Variables in Java Assignment Directions Use the NetBeans IDE to create a Java program using the skeleton code in this lesson as a model. Create code...
- C Computers and Technology The second team to speak in a debate offers what to attempt to weaken the constructive argument...
- M Mathematics Explain how to determine if a question is asking for volume or surface area. VE...
- E English I need some help on some 12 night Shakespeare questions!!...
- M Mathematics Why do polar substances dissolve in water? Water molecules break apart polar molecules. Water molecules are attracted to polar molecules and surround them. Water...
- E English What is most closely the meaning of ghastly as it is used in the following passage? By The grave and stern the corm of the continents it wore, “though thy crest be...
- B Biology What is a offspring produced by parent with different forms of the same trait?...
- B Biology What is a thermocline...
- E English What abilities/talents might a poet or short story writer possess that a novelist, even one as talented as Faulkner, might be missing?...
- M Mathematics Can’t find the answer to this someone help me!!...
Ответ: