Question: Write a Java program that implements a queue in a hospital. I want your program to ask the user to enter the number of patients

Write a Java program that implements a queue in a hospital. I want your program to ask the user to enter the number of patients then enter the patient number starting from 110 till the end of the queue then print number of patients waiting in the queue.

Complete the following exercises pasted below:

Q1. Suppose an initially empty stack S has performed a total of 25 push operations, 12 top operations, and 10 pop operations, 3 of which returned null to indicate an empty stack. What is the current size of S?

Q2. What values are returned during the following series of stack operations, if executed upon an initially empty stack?

push(5), push(3), pop(), push(2), push(8),

pop(), pop(), push(9), push(1), pop(),

push(7), push(6), pop(), pop(), push(4),

pop(), pop().

Q3. Implement a method with signature transfer(S, T) that transfers all elements from stack S onto stack T, so that the element that starts at the top of S is the first to be inserted onto T, and the element at the bottom of S ends up at the top of T.

Q4. What values are returned during the following sequence of queue operations, if executed on an initially empty queue?

enqueue(5), enqueue(3), dequeue(),

enqueue(2), enqueue(8), dequeue(), dequeue(), enqueue(9), enqueue(1),

dequeue(), enqueue(7), enqueue(6), dequeue(), dequeue(), enqueue(4),

dequeue(), dequeue().

Q5. Suppose you have a non-empty stack S of type integers. Write a method that searches and removes value X in the stack S. Make sure the order of items in the stack are unchanged. If X is not found the method returns false, otherwise true.

Q6. Repeat Q5 for a queue.

in java

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!