Ruby | SizedQueue max() function
Last Updated :
09 Jan, 2020
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:
#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
|
Output:
3
3
Example 2:
#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
|
Output:
6
6
Reference: https://devdocs.io/ruby~2.5/sizedqueue#method-i-max
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...