Ruby | SizedQueue max() function

The max() is an inbuilt function in Ruby returns the maximum size of the SizedQueue. It returns the size using which the Queue was initialised.

Syntax: sq_name.max()

Parameters: The function does not takes any parameter.

Return Value: It returns the size of the SizedQueue.

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

#Ruby program for max() function in SizedQueue
  
#Create a new SizedQueue q1
sq1 = SizedQueue.new(3)
  
#pushes 5
          sq1.enq(5)
  
#pushes 6
              sq1.enq(6)
  
#Prints the max size
                  puts sq1.max
  
#Pops the element
                      sq1.pop
  
#Prints the max size
                          puts sq1.max

chevron_right


Output:

3
3

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

#Ruby program for max() function in SizedQueue
  
#Create a new SizedQueue q1
sq1 = SizedQueue.new(6)
  
#pushes 5
          sq1.enq(5)
  
#pushes 6
              sq1.enq(6)
  
#pushes 7
                  sq1.enq(7)
  
#Prints the length
                      puts sq1.max
  
#Pops the element
                          sq1.pop
  
#Prints the length
                              puts sq1.max

chevron_right


Output:

6
6

Reference: https://devdocs.io/ruby~2.5/sizedqueue#method-i-max




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.