Stacks and Queue

Stack: Introduction

Stacks are a data structure that are similar to lists. The difference is that they are FILO (first in last out). A simple real-world example of a stack would be a can of tennis balls. If you put balls numbered 1, 2, and 3 in that order into a tennis ball can. they can only be removed in the order 3, 2, 1. (See reference). Stacks have method called push and pop.

tennis balls alt

Stack: Constructor

Stack: Push

Stack: Pop

Queue: Introduction

Queues are FIFO (first in first out). A simple real-world example of a queue would be a line of people waiting to get in a bus. If you put people in the line in the order 1, 2, and 3, they can only be removed in the order 1, 2, and 3. (See reference). Queues have method called enqueue and dequeue.

Queue: Constructor

Queue: Enqueue

Queue: Dequeue

Last updated