Terminology / naming convention for queue / API operations?

Queue, or FIFO, is one of the most common data structures and has built-in implementations in many languages ​​and frameworks. However, there seems to be little consensus on what the main operations of the queue should be called. An overview of several popular languages ​​shows:

  • Python: put / get
  • C #, Qt: enqueue / dequeue
  • Ruby, C ++ STD: push / pop
  • Java: add / remove

If you need to implement a queue (say, in some embedded platform that no longer has an implementation of its own queue), what naming convention would be best? Enqueue / dequeue seem most explicit, but verbose; put / get is concise, but gives no hint as to the nature of the FIFO operations; push / pop seems to imply a stack operation instead of queue operations.

+6
terminology data-structures queue naming-conventions
source share
8 answers

I'm a kind of pedant, so I would go with enqueue/dequeue .

Although add/next has a certain appeal.

Just to tempt the problem a bit more, in Perl it push/shift . :)

+4
source share

push / pop is clearly not true for fifo, as these are stacks (first in last).

Turn

can refer to an object, as well as an operation, so the bit is overloaded, and dequeue can cause confusion, since it is usually used to refer to a double-ended queue.

put / get - short, obvious and general (does not imply implementation and can be used for all kinds of queues / lists / collections) - what do you dislike?

+2
source share

I will probably call it push_back and pop_front .

+1
source share

Add / remove sounds as the most logical to use, especially if you are going to read it so that it is not read by people unfamiliar with the structure or language (easier to understand).

Push / Pop will be next in my ranking due to personal preferences.

It relies / get.

Enqueue / Dequeue is the last because I really hate the letter Q.

0
source share

Add / remove has the advantage that you can easily switch from a queue to another data structure.

For example, storing states in a queue compared to the stack makes the difference between the first and in-depth searches.

0
source share

I like enqueue and dequeue, but typing them sucks. Therefore, in my queue structures (both in C ++ and Java), I called the functions enQ and deQ :)

0
source share

Pop / push does not sound right as it offers a stack data structure instead of a queue.

To add something new to the sentences: my teachers always used in and out on the board.

0
source share

I like to get in and decapitate. Not for all. Or "with the new", "with the old." And then for us the southwestern have berattle and defang. But my favorite graphic. Right arrow for right arrow and then right arrow.

0
source share

All Articles