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, 22.06.2019 06:00
Write a program that uses a widgetviewer object to do the following: generate two random integers between 1 and 9 (inclusive). name one of them x, the other y. display them to the user using jlabel objects. create a jlabel object displaying the text "enter an operation number." create a jtextfield for the user's input. create a jbutton displaying the text "press here when you've entered your operation." use addandwait to add it to the widgetviewer object. when the user clicks the jbutton, evaluate operation in the following order to determine the one and only mathematical operation to perform on x and y. use a jlabel to display the result. if operation is between 1 and 10 inclusive, add x and y. if operation is evenly divisible by 4, subtract y from x. if operation is evenly divisible by 5, use integer division to divide y into x. if operation is an even number, use floating point division to divide y into x. if none of the other tests on operation apply, multiply x and y. note: operation can be negative or zero.
Answers: 2
question
Computers and Technology, 22.06.2019 23:00
Is an attack that relies on guessing the isns of tcp packets
Answers: 2
question
Computers and Technology, 23.06.2019 16:30
How to do this programming flowchart?
Answers: 3
question
Computers and Technology, 24.06.2019 15:30
Python. primary u.s. interstate highways are numbered 1-99. odd numbers (like the 5 or 95) go north/south, and evens (like the 10 or 90) go east/west. auxiliary highways are numbered 100-999, and service the primary highway indicated by the rightmost two digits. thus, the 405 services the 5, and the 290 services the 90. given a highway number, indicate whether it is a primary or auxiliary highway. if auxiliary, indicate what primary highway it serves. also indicate if the (primary) highway runs north/south or east/west.
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
Mathematics, 06.02.2021 21:50
question
English, 06.02.2021 21:50
question
Chemistry, 06.02.2021 21:50
question
Spanish, 06.02.2021 21:50
question
Mathematics, 06.02.2021 21:50
question
Mathematics, 06.02.2021 21:50
Questions on the website: 13722367