Docsity

Queues and Stacks: FIFO and FILO Data Structures, Slides of Data Structures and Algorithms

Partial preview of the text

Download Queues and Stacks: FIFO and FILO Data Structures and more Slides Data Structures and Algorithms in PDF only on Docsity!

Queues and Stacks

Queues

  • Queues are very simple FIFO (First In First Out) Data Types.
  • Queues have two basic functions:
    • Enqueue (insert object into queue)
    • Dequeue (remove object from queue)

Queues

  • Dequeue simply reverses the process by removing the front object (object inserted first) from the queue.

Queues

  • Applications of queues
    • Printer queues
    • Socket queues
    • File server queues
    • Any real life line (first come first serve)

Queue

  • Linked List representation:

Queue

  • Linked List representation after one dequeue:

Stacks

  • Here is a stack after a series of pushes

Stacks

  • When popped the C would come first then the B then the A.

Stack

  • Linked List implementation:

Stack

  • Linked List representation after popping