IB Computer Science 2

From WLCS
Revision as of 12:17, 17 October 2012 by Admin (talk | contribs)

Wednesday (10/17/12)

Warmup:

  • Draw the memory diagram for the following code:
Node top = null;
top = new Node(20);
Node bottom = top;
top.next = new Node(12);
bottom = bottom.next;
bottom.next = new Node(13);
bottom.next.next = null;

Agenda:

  • Demo Media:DynamicStack.java
  • Review Dynamic Queue
    • Memory diagrams for each method
    • Begin/Starting scenarios for each method
    • Draw the before-and-after pictures for adding a Node to an empty Queue (be sure to use head and tail!)
    • Draw the before and after pictures for adding a Node to a non-empty Queue
    • Draw the before-and-after pictures for removing a Node from an empty Queue
    • Draw the before and after pictures for removing a Node from a non-empty Queue
  • Complete and demo Media:DynamicQueue.java

Homework:

Monday (10/15/12)

Warmup:

  • Draw the memory diagram for the following code:
Node x = new Node();
x.num = 5;
Node y = new Node();
y.num = 8;
y.next = x;
x.next = null;

Agenda:

  • Node references practice
    1. Pair up
    2. Each person should type up an example main that uses Nodes
    3. Each person should then draw the memory diagram of the other person's code
    4. Repeat!
  • Everybody must be an expert using Nodes and references
  • Node Quiz
  • Static vs. Dynamic
  • Dynamically-sized Stacks
    • Stack scenarios and Before-&-After pictures
      1. What are the possible scenarios?
      2. What does the picture look like Before?
      3. What does the picture look like After?
    • Create a new class called DynamicStack
    • What attribute must we keep track of when we talk about stacks?
    • Create a Node reference for the most important stack attribute
    • Implement void push(int num) using Nodes.
      • push() should not return anything
      • push() creates a new Node with the num, 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 top(), which should just return the value on top of the stack
      • If the stack is empty, then return some error code
    • Implement isEmpty() which returns true if the stack is empty, and false otherwise
    • Implement print() which should print your entire stack
    • TEST YOUR STACK USING MR. BUI'S ORIGINAL STACK MAIN OR YOUR OWN MAIN METHOD
      • 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

Thursday (10/11/12)

  • What does FIFO stand for?
  • When would you want to use a queue? Give an example
  • Assume the following queue operations have occurred:
    1. Add "Hyde"
    2. Add "Bradfield"
    3. Add "Infantino"
    4. Remove
    5. Add "Silverman"
    6. Remove
    7. What is left in the queue?

Agenda:

Homework:

  • Node Quiz on Monday (10/15/12)

Tuesday (10/9/12)

Agenda:

Thursday (10/4/12)

Agenda:

Homework:

Archives