Prgr 2 3. You have a situation where you need to use two stacks. You know that t
ID: 3725883 • Letter: P
Question
Prgr 2 3. You have a situation where you need to use two stacks. You know that together they never have more than MAX elements. You decide to use an array representation with both stacks residing in the same armay but with two logical pointers to top, fopt (for stackt) and top2(for stackz). Stackt grows from left to right, stack2 grows from right to left. Notice this is not a linked list. Use the folowing detnitions and declarations. Note that the stack is being passed as a parameter to these functions; they are not member functions of a class assume that when the parameter is stack 1, the user passes the stack where the top is topf and that when the parameter is slock2, the user passes the stack where the top is top2 Fill in the blank in the code below. (5 points each) . You may const MAX 100 typedef int ItemType struct StackType l components on the stacks ItemType info[MAX]: int topt int top2; Il top for stackt l top for stack2 vold CreateStack1(StackType& stack1) W Post: stack1 has been set to empty vold CreateStack2(StackType& stack2) W Post: stack2 has been set to empty 2 Boolean IsFull(StackType stack) Il Pre: stack has been created. l Post: return FALSE if there is room for another item; TRUE otherwise. 3 4. Consider the implementation of queues by usin REAR -, (4 points each) 5. Consider the implementation of queues by using arrays with the size of 6. After you add and remove items couple of times, the current content in the queue shown as below, what is FRONT>- __ and REAR each) =_?(3 points er the implementation of queues by using arrays with the size of 6. After you add and remove items couple of times, the current content in the queue shown as below, what is FRONT >- _ and REARs- -' (3 points 7. Fill in the blanks to complete this C++ program. (5 points each) # ifndef STACK ARRAYSH # define STACK-ARRAYS-H -Explanation / Answer
3. // 1 First Blank Value void CreateStack1(StackType &stack1) { top1 = -1; } Reason : for creating a stack left to right empty we have to set top = -1 because when we starts push the values in stack they starts with top = 1. // 2 Second Blank void CreateStack2(StackType &stack2) { // max = 100 value // stack 2 right to left so top set to max top2 = MAX; } Reason : for creating a stack right to left empty we have to set top = size because when we starts push the values in stack they starts with top = size index. //3 third Boolean isFull(StackType stack) { // for stack 1 return stack.top >= MAX ? true : false; } Reason : check if top is greater than or equal to max then this ia full // for stack 2 return stack.topRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.