Algorithms and OOD (CSC 207 2013F) : EBoards

CSC207.01 2013F, Class 32: Merge Sort


Overview

Admin

A C Problem

char *
foo(char *t, char *s) 
{
  while (*t++ = *s++) 
    ;
  return t;
} // for

Ushahidi and the Project

HW 7

Due tonight

Why implement java.util.Iterator when we have cursors?

Real Java programmers build iterators for any collection class they design

public class MyIterator<T> implements java.util.Iterator<T> {
     // +--------+----------------------------------------------------------
     // | Fields |
     // +--------+

    Node<T> pos;

     // +--------------+----------------------------------------------------
     // | Constructors |
     // +--------------+

     // +---------+---------------------------------------------------------
     // | Methods |
     // +---------+

    public T next() {
         // Find out what's right after pos
         // Advance the position
         // Return the value we got in step 1
    }
    public boolean hasNext() {
    }

    public void remove() {
         throw new UnsupportedOperationException();
    }
}

Once you've implemented iterators, folks can write

DoublyLinkedList dll;
for (val : dll) {
}

_When should I put the type variable in brackets?

Usually, whenever you are referring to a generic/parameterized class.

Not when you are using it as a type

So

public T extractValue(Node<T> node)

Also when parameterizing static methods

public static <T> returnType methodName(...)

Exam

Any hints on DNF?

Write isDNF

HW 8

An introduction to merge sort

Analyzing merge sort

Lab

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 http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.