Assume we already have the Stack interface code and the class Stack Array code a
ID: 3836204 • Letter: A
Question
Assume we already have the Stack interface code and the class Stack Array code available. The goal of this program is to write the main code. This code should create two Stack Array objects of type String. You should then place some fruit names in one stack and some fruit names in the other stack. After the names are placed in each stack, then your code should check if the two stacks have the same fruit names in the same order. Note that after the check, the two stacks should have the same original values as before the check started.Explanation / Answer
I'm giving you the Pseudo Code here, as you didn't mention in which language you want your code.
1) Populate the values of two StackArrays A1, A2 with the desired fruit names
2) Create two temporary StackArrays TA1, TA2
3) Now pop both A1, A2 StackArrays and push into TA1, TA2 respectively.
4) After pushing to TA1 and TA2 verify if both the values pushed are equal or not
5) If both the values are equal then continue to pop the elements in A1, A2 into TA1, TA2 respectively. if both the stacks A1, A2 are finished popping then go to step7.
6) If both values are not equal then thrown an error message and go to step 7
7) Pop TA1, TA2 and push to A1, A2 respectively. (This ensures that the Stacks A1, A2 are in the same state when started)