0

I am trying to Huffman Encode and String. To do this I First store the frequency of each character in an array that looks something like this:A["Ascii value of the character"]= frequency of the character

Example: "Ascii";
A[65]=1; //A
A[115]=1 // s
A[99]=1;// c
A[105]=2;//i

I am trying to make a Priority Queue based on this array.

I have set up a CharacterObject class that has two attributes: the actual Character, and the frequency.

I have created the following PriorityQueue:

PriorityQueue<CharObject> pq= new PriorityQueue<CharObject>(pqsize); 
// pqsize is the number of distinct characters in the string 
// i want to Huffman Encode.

My question is how do I tell the The PriorityQueue that I want to Prioritize by the frequency attribute of the CharacterObject class I made so that it doesnt throw an error when i try to add the the PQ. Side note I want to implement a Min-PQ.

Ishan Patel
  • 61
  • 1
  • 6
  • [This previous question/answer](http://stackoverflow.com/questions/683041/java-how-do-i-use-a-priorityqueue) details the use of comparator and the PriorityQueue constructor. – dckuehn Apr 11 '13 at 04:57
  • Make a `Comparator` that does the comparison you want – Patashu Apr 11 '13 at 05:29

0 Answers0