Question: Write a function isSimilar that takes a Queue and a Stack as parameters (containing the same type of elements) and returns true if all the

Write a function isSimilar that takes a Queue and a Stack as parameters (containing the same type of elements) and returns true if all the elements of stack is contained in the queue. The order of elements does not matter. For example, the following would return true if passed as parameters to your method:

queue: front [1, 9, 3, 4, 5] rear

stack: bottom [4, 5, 1, 9, 3] top

The following parameters would return false, because the element 6 from the stack is not contained in the queue and the element 3 from the queue is not contained in the stack:

queue: front [1,2 ,3 ,7 ,4 ] rear

stack: bottom [6,1 ,2 ,4 ,7 ] top

You may use stack or queue as auxiliary storage. Assumptions: all valid operations for stack and queue are availableitems contained in both structure are not repeated.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!