Ruby | Queue push() function
The push() is an inbuilt function in Ruby inserts the element in the queue.
Syntax: q_name.push(element)
Parameters: The function takes the element to be inserted into the queue.
Return Value: It inserts the element into the queue.
Example 1:
Ruby
q1 = Queue. new
q1.push( 5 )
q1.push( 6 )
puts q1.pop
puts q1.pop
|
Output:
5
6
Example 2:
Ruby
q1 = Queue. new
q1.push( 10 )
q1.push( 12 )
puts q1.pop
q1.push( 13 )
puts q1.pop
puts q1.pop
|
Output:
10
12
13
Reference: https://devdocs.io/ruby~2.5/queue#method-i-push
Last Updated :
04 Dec, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...