Read 10 Stacks and Ques - 401-advanced-javascript-hanna-alemu/seattle-javascript-401d31 GitHub Wiki

What is a Stack?

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

Common terminology for a stack is

  • Push - Nodes or items that are put into the stack are pushed

  • Pop - Nodes or items that are removed from the stack are popped

  • Top - This is the top of the stack.

  • isEmpty - checks if the stack is empty or not.

  • Peek - When you Peek you will view the Top node in the stack. If the stack is empty, and you don’t Peek, you will receive a NullReferenceException if you attempt to Pop. Stacks follow these concepts:

  • FILO concept: First In Last Out. This means that the first item in the stack, will be the last item out.

  • LIFO concept: Last In First Out This means that the last item in the stack, will be the first item out.

What is a Queue?

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.
  • 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 Top node in the stack. If the stack is empty, and you don’t Peek, you will receive a NullReferenceException.

Queues follow these concepts:

  • FIFO - First In First Out - This means that the first item in the queue will be the first item out of the queue.
  • LILO - Last In Last Out - This means that the last item in the queue will be the last item out of the queue.