Skip to content

Latest commit

 

History

History
63 lines (45 loc) · 1.82 KB

stack.md

File metadata and controls

63 lines (45 loc) · 1.82 KB

Stacks

Projected Time

30-45 minutes

Prerequisites

JS Functional programming

Motivation

Stack is one of the most commonly used data structure along with its opposite relative, queue. Understanding how to implement stack helps you better understand and describe insertion, removal, and organization of data in a seqential order.

Objectives

Explain what a stack data structure is and show how it is implemented.

Specific Things To Teach

  • Definition of stack
  • Show an example of stack data structure
  • JavaScript methods used to implement stack

Materials

Lesson

  • Lesson slides: WIP
  • Lesson video: WIP

Make sure to mention these things:

  • Explain what LIFO and FILO means.
  • Differentiate stack and queue.

Common Mistakes / Misconceptions

  • Array and stack seem similar at first glance. While stack can be implemented using array, the data in array can be access randomly whereas stack must be access according to order.

Guided Practice

Explain and discuss as a class the steps involved in writing a stack structure, including:

  • Constructor
  • Push/Enqueue
  • Pop/Dequeue
  • Size control

Independent Practice

Try to write a Stack class with the steps discuss as methods:

var Stack = function() {}
  // Constructor

  // Push

  // Pop

  // Size management of stack

  // Output of stack
}

Challenge / Check for Understanding

Find a partner and show each other your own Stack class. Explain how the class you wrote works.