The queue.empty?
function in Ruby returns a true
value if the queue is empty; otherwise, it returns false
. In short, this function is used to check if the queue is empty or not.
Figure 1 shows the visual representation of the queue.empty?
function.
Note: Queue is a data structure in Ruby that acts as a waiting list and uses the
approach. FIFO first-in-first-out
queue_name.empty?
# where the queue_name is the name of the queue
This function does not require a parameter.
If the queue is empty, the queue.empty?
function returns a true
value. Otherwise, it returns false
.
# two queues# filled queuequeue1 = Queue.newqueue1.push(1)queue1.push(3)queue1.push(5)queue1.push(2)queue1.push(4)print "The queue1 is empty : ", queue1.empty?, "\n"# empty queuequeue2 = Queue.newprint "The queue2 is empty : ", queue2.empty?, "\n"