Open In App

Ruby | Queue new() function

Last Updated : 07 Jan, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
The new() is an inbuilt function in Ruby creates a new queue of the given name.
Syntax: q_name = Queue.new() Parameters: The function does not takes any parameter. Return Value: It creates a new queue.
Example 1: CPP
#Ruby program for new () function in Queue

#Create a new QUEUE q1
q1 = Queue.new

#pushes 5
     q1.enq(5)

#Create a new QUEUE q2
         q2
    = Queue.new

#pushes 15
      q2.enq(15)

#pushes 16
          q2.enq(16)

#Prints the length of q1
              puts q1.length

#Prints the length of q2
                  puts q2.length
Output:
1
2
Example 2: CPP
#Ruby program for new () function in Queue

#Create a new QUEUE q1
q1 = Queue.new

#Create a new QUEUE q2
     q2
    = Queue.new

#Prints the length of q1
      puts q1.length

#Prints the length of q2
          puts q2.length
Output:
0
0
Reference: https://devdocs.io/ruby~2.5/queue#method-c-new

Next Article

Similar Reads