Algorithms and OOD (CSC 207 2013F) : EBoards

CSC207.01 2013F, Class 51: Pause for Breath




Questions on the Homework

What simple tests?

{ }
{ "sam":"rebelsky" }
{ "samr" : { "fname":"Sam", "lname":"Rebelsky", "ryphot":0 } }

What do we return?

Mostly dictionary-like thingys

Also arrays of those

You might create MyJSONObject and MyJSONArray

Thinking about memory

Memory associated with your program has three parts

Sample code!

public class Counter {
    static int operations = 0;
    int counter;
    void increment() {
    } // increment()

    void decrement() {
    } // decrement()

    int get() {
        return this.counter;
    } // get()
} // class Counter

public class CounterExpt {
    public static void main(String[] args) {
        Counter c1 = new Counter();
        Counter c2 = new Counter();
        Counter c3 = c1;


        System.out.println("ops: " + Counter.operations);
        System.out.println("c1: " + c1.get());
        System.out.println("c2: " + c2.get());
        System.out.println("c3: " + c3.get());
        System.out.println("ops: " + Counter.operations);
    } // main
} // class CounterExpt

Why doesn't this code do what we expect?

// Replace a tree by its right subtree
tree = tree.larger;

It doesn't work because it's pointer assignment (see whiteboard)

Is there a *tree = *tree.larger in Java? NO

We also can't explicitly get the address of something.

Why do we not allow such assignments?


class Foo {
    int x;
class Bar extends Foo {
    int y;
Foo foo = new Foo();
Foo bar = new Bar();
*foo = *bar;        // What does this really mean?

Loop invariants

Data structure invariants

Copyright (c) 2013 Samuel A. Rebelsky.

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.