Open In App

Ruby | SizedQueue push() function

Last Updated : 09 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
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:




#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:




#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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads