< inputText.length(); i++) {tempChar = inputText.charAt(i);tempCharIndex = (int) tempChar;System.out.println("" + tempCharIndex + " ");tempCharCounts[tempCharIndex]++;} // Of for i// Step 2. Scan to determine the size of the alphabet.alphabetLength = 0;for (int i = 0; i < 255; i++) {if (tempCharCounts[i] > 0) {alphabetLength++;} // Of if} // Of for i// Step 3. Comparess to the alphabetalphabet = new char[alphabetLength];charCounts = new int[2 * alphabetLength - 1];int tempCounter = 0;for (int i = 0; i < NUM_CHARS; i++) {if (tempCharCounts[i] > 0) {alphabet[tempCounter] = (char) i;charCounts[tempCounter] = tempCharCounts[i];charMapping[i] = tempCounter;tempCounter++;} // Of if} // Of for iSystem.out.println("The alphabet is: " + Arrays.toString(alphabet));System.out.println("Their count are: " + Arrays.toString(charCounts));System.out.println("The char mappings are: " + Arrays.toString(charMapping));} // Of consructAlphabet/********************** Construct the tree.********************/public void constrcuTree() {// Step 1. Allocate space.nodes = new HuffmanNode[alphabetLength * 2 - 1];boolean[] tempProcessed = new boolean[alphabetLength * 2 - 1];// Step 2. Initialize leaves.for (int i = 0; i < alphabetLength; i++) {nodes[i] = new HuffmanNode(alphabet[i], charCounts[i], null, null, null);} // Of for i// Step 3. Construct the tree.int tempLeft, tempRight, tempMinimal;for (int i = alphabetLength; i < alphabetLength * 2 - 1; i++) {// Step 3.1 Select the first minimal as the left child.tempLeft = -1;tempMinimal = Integer.MAX_VALUE;for (int j = 0; j < i; j++) {if (tempProcessed[j]) {continue;} // Of ifif (tempMinimal > charCounts[j]) {tempMinimal = charCounts[j];tempLeft = j;} // Of if} // Of for jtempProcessed[tempLeft] = true;// Step 3.2 Select the second minimal as the right child.tempRight = -1;tempMinimal = Integer.MAX_VALUE;for (int j = 0; j < i; j++) {if (tempProcessed[j]) {continue;} // Of ifif (tempMinimal > charCounts[j]) {tempMinimal = charCounts[j];tempRight = j;} // Of if} // Of for jtempProcessed[tempRight] = true;System.out.println("Selecting " + tempLeft + " and " + tempRight);// Step 3.3 Construct the new node.charCounts[i] = charCounts[tempLeft] + charCounts[tempRight];nodes[i] = new HuffmanNode('*', charCounts[i], nodes[tempLeft], nodes[tempRight], null);// Step 3.4 Link with children.nodes[tempLeft].parent = nodes[i];nodes[tempRight].parent = nodes[i];System.out.println("The children of " + i + " are " + tempLeft + " and " + tempRight);} // Of for i} // Of constructTree/********************** Get the root of the binary tree.* * @return The root.********************/public HuffmanNode getRoot() {return nodes[nodes.length - 1];} // Of getRoot/********************** Pre-order visit.********************/public void preOrderVisit(HuffmanNode paraNode) {System.out.println("(" + paraNode.character + ", " + paraNode.weight + ")");if (paraNode.leftChild != null) {preOrderVisit(paraNode.leftChild);} // Of ifif (paraNode.rightChild != null) {preOrderVisit(paraNode.rightChild);} // Of if} // Of preOrderVisit/********************** Generate codes for each character in the alphabet.********************/public void generateCodes() {huffmanCodes = new String[alphabetLength];HuffmanNode tempNode;for (int i = 0; i < alphabetLength; i++) {tempNode = nodes[i];//Use tempCharCode instead of tempCode such that it is unlike//tempNode.//This is an advantage of long names.String tempCharCode = "";while (tempNode.parent != null) {if (tempNode == tempNode.parent.leftChild) {tempCharCode = "0" + tempCharCode;} else {tempCharCode = "1" + tempCharCode;} // Of iftempNode = tempNode.parent;} // Of whilehuffmanCodes[i] = tempCharCode;System.out.println("The code of " + alphabet[i] + " is " + tempCharCode);} // Of for i} // Of generateCodes/********************** Encode the given string.* * @param paraString*The given string.********************/public String coding(String paraString) {String resultCodeString = "";int tempIndex;for (int i = 0; i < paraString.length(); i++) {// From the original char to the location in the alphabet.tempIndex = charMapping[(int) paraString.charAt(i)];// From the location in the alphabet to the code.resultCodeString += huffmanCodes[tempIndex];} // Of for ireturn resultCodeString;} // Of coding/********************** Decode the given string.* * @param paraString*The given string.********************/public String decoding(String paraString) {String resultCodeString = "";HuffmanNode tempNode = getRoot();for (int i = 0; i