Ruby | SizedQueue new() function

The new() is an inbuilt function in Ruby creates a new SizedQueue of the given name.

Syntax: q_name = SizedQueue.new()

Parameters: The function does not takes any parameter.

Return Value: It creates a new SizedQueue.

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

#Ruby program for new () function in SizedQueue
  
#Create a new SizedQueue sq1
sq1 = SizedQueue.new(1)
  
#pushes 5
          sq1.enq(5)
  
#Create a new SizedQueue sq2
              sq2
    = SizedQueue.new(2)
  
#pushes 15
          sq2.enq(15)
  
#pushes 16
              sq2.enq(16)
  
#Prints the length of sq1
                  puts sq1.length
  
#Prints the length of sq2
                      puts sq2.length

chevron_right


Output:

1
2

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

#Ruby program for new () function in SizedQueue
  
#Create a new SizedQueue sq1
sq1 = SizedQueue.new(10)
  
#Create a new SizedQueue sq2
          sq2
    = SizedQueue.new(19)
  
#Prints the length of sq1
          puts sq1.length
  
#Prints the length of sq2
              puts sq2.length

chevron_right


Output:

0
0

Reference: https://devdocs.io/ruby~2.5/sizedqueue#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.