Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

ruby
queue
communitycreator

What is queue.deq() in Ruby?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The queue.deq() function in Ruby returns the element that is available in the front of the queue, and then removes it from the queue.

Figure 1 shows the visual representation of the queue.deq() function.

Figure 1: Visual representation of queue.deq() function

This function is equivalent to queue.pop().

Syntax

queue_name.deq()
# where the queue_name is the name of the queue

Parameter

This function does not require a parameter.

Return value

This function returns the element that is at the front of the queue.

Example


#Returns the head of queue and removes it from queue
queue1=Queue.new
queue1.push(1)
queue1.push(3)
queue1.push(5)
queue1.push(2)
queue1.push(0)
#queue1 = 1->3->5->2->0
print "The length of queue1 before deq : ", queue1.length(), "\n"
#after deq queue1 = 3->5->2->0
print "The queue1.deq() : ", queue1.deq(), "\n"
print "The length of queue1 after deq : ", queue1.length(), "\n"

RELATED TAGS

ruby
queue
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring