{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

day23 - COP 3503 Computer Science II CLASS NOTES DAY#23...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
COP 3503 – Computer Science II CLASS NOTES - DAY #23 Huffman Coding Tree public class HuffNode { protected boolean children; protected char root; protected HuffNode left; protected HuffNode right; public HuffNode ( ) { children = false; root = null; left = null; right = null; } // end constructor public HuffNode (char in, HuffNode lef, HuffNode rig) { children = true; root = in; left = lef; right = rig; } // end constructor } // end HuffNode public class Hufflist { protected HuffNode head; protected HuffNode current; protected String answer; public HuffList ( ) { head = new HuffNode ( ); current = head; answer = new String ( ); } // end constructor Day 23 - 1
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
public void insertAll (char[ ] alpha) { for (int i = 0; i < 26; i++) { HuffNode temp = new HuffNode (alpha[i], null, null) if ((i % 2) == 0) { current.left = temp; } else{ current.right= temp; current = getNextParent ( ); } //end else } //end for current = head; } // end insertAll public boolean find (HuffNode h, char c) { if (h.root == c) return true; if (find (h.left, c)) { answer = “0” + answer; return true; } if (find (h.right, c)) { answer = “1” + answer; return true; } return false; } // end find } // end HuffList.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}