The queue.push()
function in Ruby is used to insert an element at the back of the queue.
Figure 1 shows the visual representation of the queue.push()
function.
This function is equivalent to
queue.enq()
.
queue_name.push(element)
# where the queue_name is the name of the queue
This function requires an element
as a parameter.
This function inserts the element
sent as a parameter at the back of the queue.
#Inserts elements in the queuequeue1=Queue.newqueue1.push(1)queue1.push(3)queue1.push(5)queue1.push(2)queue1.push(0)#queue1 = 1->3->5->2->0print "The queue1 after series of push : \n"print queue1.pop(),"->",queue1.pop(),"->",queue1.pop(),"->",queue1.pop(),"->",queue1.pop()