Java - Dynamic Stack Assignment

From WLCS
Revision as of 15:53, 9 November 2016 by Admin (talk | contribs) (Created page with "== Objectives == * You will implement a dynamically-sized queue using linked Nodes * You will implement queue methods (enqueue/add, dequeue/remove, etc.) * You will test your...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Objectives

  • You will implement a dynamically-sized queue using linked Nodes
  • You will implement queue methods (enqueue/add, dequeue/remove, etc.)
  • You will test your dynamic queue in a main() method

Resources

Directions

Before & After Visualizations

  1. Take out a pencil and paper or a dry-erase board and marker
  2. Load the Dynamic Stack Visualization
  3. Consider each of the following questions and use the visualization tool to help you answer them. Practice drawing each of the visualizations yourself.
    • What does an empty stack look like? (The top reference variable is null)
    • For each of the following actions, assess what the picture looks like Before? then After? What changes occurred to make the Before image become the After image?
      • push(4)
      • push(2)
      • pop()
      • pop()

Dynamic Stack class

  1. Create a new class called DynamicStack

Attributes

  • What attribute must we keep track of when we talk about stacks? (Hint: rhymes with "mop")
  • Create a Node reference for the most important stack attribute

Methods

    • Implement void push(data) using Nodes.
      • push() should not return anything
      • push() creates a new Node with the data parameter, and set the new Node's next reference to the top
      • Don't forget to update the top to be the new node!
    • Implement int pop() using Nodes
      • pop() removes the value on top of the stack, return it
      • pop() should also update the top
      • pop() returns null if the stack is empty
    • Implement isEmpty() which returns true if the stack is empty, and false otherwise
    • Implement print() which should print your entire stack from top down (to null)
    • TEST YOUR STACK
      • Be sure to push A LOT of data to test the dynamic size
      • Also test popping A LOT of data to make sure it works too