Ruby | SizedQueue << function
Last Updated :
09 Jan, 2020
Improve
The <<() is an inbuilt function in Ruby inserts the element in the SizedQueue. The SizedQueue have a particular capacity and cannot accept elements once it is full.
CPP
Output:
CPP
Output:
Syntax: sq_name << element Parameters: The function takes the element to be inserted into the SizedQueue. Return Value: It inserts the element into the SizedQueue.Example 1:
#Ruby program for << function in SizedQueue
#Create a new SizedQUEUE q1
q1 = SizedQueue.new(2)
#push 5
q1
<< 5
#push 6
q1
<< 6
#Prints the element
puts q1.pop
puts q1.pop
5 6Example 2:
#Ruby program for << function in SizedQueue
#Create a new SizedQUEUE q1
q1 = SizedQueue.new(3)
#push 15
q1
<< 15
#push 16
q1
<< 16
#push 17
q1
<< 17
#Prints the element
puts q1.pop
puts q1.pop
puts q1.pop
15 16 17Reference: https://devdocs.io/ruby~2.5/sizedqueue#method-i-3C-3C