Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4. Given the following applications, give a suitable lata structure far each a)

ID: 3699132 • Letter: 4

Question

4. Given the following applications, give a suitable lata structure far each a) Maintain a waiting list for reservations at a hotel. Rooms are b) Maintain a list of violin players who auditioned for the NJ cAttempt to find an escape route for a mouse in a maze. The assigned on a first-come, first-served basis. Sympbony brchestra. The players were ranked during their auditions, and the top- ranked player will get offered any job that opens up. mousé should be able to retrace its steps while attempting to escape. aXd. -d) Store the moves in a chess game. The program should allow a rto vidw the game later on. -e) Gamblers take numbers in the Powerball Lottery and win if theiy nungbers are selected 5. Consider a stack s and queue q of integers. Given the following code segment: q = new LinkedList(); s = new Stack

Explanation / Answer

5) After first Loop
1 2 3 4 is pushed into stack with 4 at the TOP
Queue is empty  

Second Loop :
4 is Even , So its added to Queue
1 2 3 => stack with 3 at the TOP
Queue has [4 ]  

Third Loop :
3 is Odd , So element 4 is removed from Queue and added to stack
1 2 4 => stack with 4 at the TOP
Queue is empty [ ]  

Fourth Loop :
4 is Even , So its added to Queue
1 2 => stack with 2 at the TOP
Queue is empty [4 ]  


6)
2 3 8 * + 4 48 4 2 + / 6 * + -
=> 2 is pushed on to stack as its an operand
=> 3 is pushed on to stack as its an operand
=> 8 is pushed on to stack as its an operand
=> When we get * as its an operator we pop two elements evaluate them and push into stack
=> 3 and 8 are popped, 3*8 = 24 and 24 is pushed ..Stack contains 2 24
=> When we get + as its an operator we pop two elements evaluate them and push into stack
=> 2 and 24 are popped, 2 + 24 = 26 and 26 is pushed ..Stack contains 26
=> 4 is pushed on to stack as its an operand
=> 48 is pushed on to stack as its an operand
=> 4 is pushed on to stack as its an operand
=> 2 is pushed on to stack as its an operand
=> When we get + as its an operator we pop two elements evaluate them and push into stack
=> 2 and 4 are popped, 2 + 4 = 6 and 6 is pushed ..Stack contains 26 4 48 6
=> When we get / as its an operator we pop two elements evaluate them and push into stack
=> 48 and 6 are popped, 48 / 6 = 8 and 8 is pushed ..Stack contains 26 4 8
=> 6 is pushed on to stack as its an operand
=> When we get * as its an operator we pop two elements evaluate them and push into stack
=> 6 and 8 are popped,6*8 = 48 and 48 is pushed ..Stack contains 26 4 48
=> When we get + as its an operator we pop two elements evaluate them and push into stack
=> 4 and 48 are popped, 4 + 48 = 52 and 52 is pushed ..Stack contains 26 52

=> When we get - as its an operator we pop two elements evaluate them and push into stack
=> 26 and 52 are popped, 26 - 52 = 26 and -26 is pushed ..Stack contains -26

Hence the Answer is -26 . ...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote