Tuesday, November 29, 2011
HW# 4.4: Modify your priority queue class so that instead of storing ints, it stores a generic, Comparable type.
what this entails:
change some ints to T
instead of if (a[i]<a[i+1])
put in
if (a[i].compareTo(a[i+1]) < 0)
Now, implement the following algorithm to **build** your HuffmanTree:
1) read your file to generate CharFreqs.
2) Take each CharFreq and put it into a new BTree, at the root. You will thus create a forest of BTree<CharFreq>s.
3) Take each BTree in that forest and insert it into your PriorityQueue.
4)
while (PQ.size() != 1)
{
BTree a = PQ.pop();
BTree b = PQ.pop();
BTree c = BTree.join(a,b);
PQ.push(c);
}
BTree huffmanTree = PQ.pop();
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment