Open In App

Ruby | SizedQueue push() function

Last Updated : 09 Jan, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
The push() is an inbuilt function in Ruby inserts the element in the SizedQueue.
Syntax: sq_name.push(element) Parameters: The function takes the element to be inserted into the SizedQueue. Return Value: It inserts the element into the SizedQueue.
Example 1: CPP
#Ruby program for push() function in SizedQueue

#Create a new SizedQueue q1
sq1 = SizedQueue.new(2)

#push 5
          sq1.push(5)

#push 6
              sq1.push(6)

#Prints the element
                  puts sq1.pop
                      puts sq1.pop
Output:
5
6
Example 2: CPP
#Ruby program for push() function in SizedQueue

#Create a new SizedQueue q1
sq1 = SizedQueue.new(2)

#push 10
          sq1.push(10)

#push 12
              sq1.push(12)

#Prints the element
                  puts sq1.pop

#Again pushes 13
                      sq1.push(13)

#Prints the element
                          puts sq1.pop

#Prints the element
                              puts sq1.pop
Output:
10
12
13
Reference: https://devdocs.io/ruby~2.5/sizedqueue#method-i-push

Next Article

Similar Reads