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:

filter_none

edit
close

play_arrow

link
brightness_4
code

#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

chevron_right


Output:

1
2

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

#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

chevron_right


Output:

0
0

Reference: https://devdocs.io/ruby~2.5/queue#method-c-new



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.