Ruby | Queue new() function
The new() is an inbuilt function in Ruby creates a new queue of the given name.
Syntax: q_name = Queue.new()
Parameters: The function does not takes any parameter.
Return Value: It creates a new queue.
Example 1:
#Ruby program for new () function in Queue
#Create a new QUEUE q1
q1 = Queue. new
#pushes 5
q1.enq(5)
#Create a new QUEUE q2
q2
= Queue. new
#pushes 15
q2.enq(15)
#pushes 16
q2.enq(16)
#Prints the length of q1
puts q1.length
#Prints the length of q2
puts q2.length
|
Output:
1
2
Example 2:
#Ruby program for new () function in Queue
#Create a new QUEUE q1
q1 = Queue. new
#Create a new QUEUE q2
q2
= Queue. new
#Prints the length of q1
puts q1.length
#Prints the length of q2
puts q2.length
|
Output:
0
0
Reference: https://devdocs.io/ruby~2.5/queue#method-c-new
Last Updated :
07 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...