Please help implement this coding assignment in Java and use the priorityQ code given below. Thank you.
Write a program to implement Huffman coding and decoding. It should do the following.
Accept a text message.
Create a huffman tree for this message
Create a code table
Encode the message into binary
Decode the message from binary back to text.
You can use String variables to store binary numbers. Don't worry about the actual bit manipulation. You can extract lines of code that we have written so far for the binary trees, to use for this project. The java code for priority Queue is given on page 147 of the textbook. Please do not use in-built data structures from the library.
PriorityQ.java
class PriorityQ
{
// array in sorted order, from max at 0 to min at size-1
private int maxSize;
private long[] queArray;
private int nItems;
public PriorityQ(int s) // constructor
{
maxSize = s;
queArray = new long[maxSize];
nItems = 0;
}
public void insert(long item) // insert item
{
int j; if(nItems==0) // if no items,
queArray[nItems++] = item; // insert at 0
else // if items,
{
for(j=nItems-1; j>=0; j--) // start at end,
{
if( item > queArray[j] ) // if new item larger,
queArray[j+1] = queArray[j]; // shift upward
else // if smaller,
break; // done shifting
} // end for
queArray[j+1] = item; // insert it
nItems++;
} // end else (nItems > 0)
} // end insert()
public long remove() // remove minimum item
{ return queArray[--nItems]; }
public long peekMin() // peek at minimum item
{ return queArray[nItems-1]; }
public boolean isEmpty() // true if queue is empty
{ return (nItems==0); }
public boolean isFull() // true if queue is full
{ return (nItems == maxSize); }
} // end class PriorityQ