Question: Using the language RUBY Create a RUBY class QUEUE that inplements methods enqueue, dequeue, and show, Instance variables are size - size of array that
Using the language RUBY Create a RUBY class QUEUE that inplements methods enqueue, dequeue, and show, Instance variables are size -
size of array that implements queue
q - array that represents queue (fixed size)
inp- index that specifies that an input value that is going in th queue should be stored in
q[inp] out- index that specifies that an output value that is leaving the queue should be taken from
q[out] empty- a logic flag which is true if the queue is empty (no elements) f
ull- logic flag which is true, if the que is full and has no free space for new elements.
The method q.enqueue(x) should store the value x in the queue q. The method x = q.dequeue should take the appropriate value from the queue q and store it in the vriable x. The method q.show should display the FIFO queue in the form <1|2|3|4|5 where 5 is the last element stored. Write a main program that creates a queue size of 5 and uses a loop to crrate the out put shown here.
<0|
<0|1|2|
<0|1|2|3|
<0|1|2|3|4|
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
