HW:
implement a binary tree class.
class BTree implements Comparable
{
int element;
BTree left, right;
}
it should be either comparable, or else
you should write a comparator for it.
http://en.wikipedia.org/wiki/Huffman_coding
my own lazy implementation of List-based stack
public class NodeStack<E> implements Stack<E> {
protected SLinkedList<E> mylist;
// protected int size; // number of elements in the stack
public NodeStack() { // constructs an empty stack mylist = SLinkedList<E>(); }
public int size() { return mylist.size(); }
public boolean isEmpty() {return mylist.isEmpty()}
public void push(E elem) { myList.insertFront(elem);}
public E top() throws EmptyStackException { if (isEmpty()) throw new EmptyStackException("empty"); return mylist.front(); }
public E pop() throws EmptyStackException { if (isEmpty()) throw new EmptyStackException("empty"); E temp = top(); myList.removeFront(); // link-out the former top node return temp; } }
It is better, IMHO
class MyVeryOwnComparator implements Comparator<T>
{
boolean compare(T o, T p)
{ Person per1 = (Person) }
}
class PQueue<T>
{
private Comparator<T> comp;
PQueue(Comparator<T> c)
{
comp = c;
}
void pop()
{
if(comp.compare(elem1, elem2)
}
}
main()
{
PQueue<Person>(new MyVeryOwnComparator())
}
Prof. Waxman,
ReplyDeleteI was just wondering, where do we submit 2.3 and 2.4 to you? The submit forms are still not on blackboard..have the due dates been extended?
now they are up.
ReplyDelete