1.

What Is Queue And Stack, List Down Their Differences?

Answer»

A collection designed for holding ELEMENTS prior to processing. Besides basic Collection OPERATIONS, queues provide additional insertion, extraction, and INSPECTION operations.

Queues typically, but do not necessarily, order elements in a FIFO (first-in-first-out) manner.

Stack is also a form of Queue but one difference, it is LIFO (last-in-first-out).

Whatever the ordering used, the head of the queue is that element which would be removed by a call to remove() or poll(). Also note that Stack and Vector are both synchronized.

Usage: Use a queue if you want to process a STREAM of incoming items in the order that they are received.Good for work lists and handling requests.

Use a stack if you want to PUSH and pop from the top of the stack only. Good for recursive algorithms.

A collection designed for holding elements prior to processing. Besides basic Collection operations, queues provide additional insertion, extraction, and inspection operations.

Queues typically, but do not necessarily, order elements in a FIFO (first-in-first-out) manner.

Stack is also a form of Queue but one difference, it is LIFO (last-in-first-out).

Whatever the ordering used, the head of the queue is that element which would be removed by a call to remove() or poll(). Also note that Stack and Vector are both synchronized.

Usage: Use a queue if you want to process a stream of incoming items in the order that they are received.Good for work lists and handling requests.

Use a stack if you want to push and pop from the top of the stack only. Good for recursive algorithms.



Discussion

No Comment Found