mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 06:23:08 +08:00
@ -35,11 +35,7 @@ public class Huffman {
|
||||
// base case; if the left and right are null
|
||||
// then its a leaf node and we print
|
||||
// the code s generated by traversing the tree.
|
||||
if (
|
||||
root.left == null &&
|
||||
root.right == null &&
|
||||
Character.isLetter(root.c)
|
||||
) {
|
||||
if (root.left == null && root.right == null && Character.isLetter(root.c)) {
|
||||
// c is the character in the node
|
||||
System.out.println(root.c + ":" + s);
|
||||
|
||||
@ -60,15 +56,12 @@ public class Huffman {
|
||||
|
||||
// number of characters.
|
||||
int n = 6;
|
||||
char[] charArray = { 'a', 'b', 'c', 'd', 'e', 'f' };
|
||||
int[] charfreq = { 5, 9, 12, 13, 16, 45 };
|
||||
char[] charArray = {'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
int[] charfreq = {5, 9, 12, 13, 16, 45};
|
||||
|
||||
// creating a priority queue q.
|
||||
// makes a min-priority queue(min-heap).
|
||||
PriorityQueue<HuffmanNode> q = new PriorityQueue<HuffmanNode>(
|
||||
n,
|
||||
new MyComparator()
|
||||
);
|
||||
PriorityQueue<HuffmanNode> q = new PriorityQueue<HuffmanNode>(n, new MyComparator());
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
// creating a Huffman node object
|
||||
|
Reference in New Issue
Block a user