Stacks and Queues

what is Stacks?

A stack is a data structure that consists of Nodes. Each Node references the next Node in the stack, but does not reference its previous

Stacks follow these concepts:

  • FILO : First In Last Out
  • LIFO : Last In First Out

  • linked

### what is Queues ? Queue is an ordered collection of items where the addition of new items happens at one end, called the “rear,” and the removal of existing items occurs at the other end, commonly called the “front.”

Common terminology for a queue is

  • Enqueue - Nodes or items that are added to the queue.
  • Dequeue - Nodes or items that are removed from the queue. If called when the queue is empty an exception will be raised.
  • Front - This is the front/first Node of the queue.
  • Rear - This is the rear/last Node of the queue.
  • Peek - When you peek you will view the value of the front Node in the queue. If called when the queue is empty an - - exception will be raised.
  • IsEmpty - returns true when queue is empty otherwise returns false.

    queue follow these concepts:

  • FILO : First In Last Out
  • LILO : Last In Last Out

what is the difference between queues and Stacks?

A stack is an ordered list of elements where all insertions and deletions are made at the same end, whereas a queue is exactly the opposite of a stack which is open at both the ends meaning one end is used to insert data while the other to remove data.

image