Hey Guys, I am building app using a huffman tree, and am building this java program to just test a few things and I am having some trouble. I have everything working except that I am having troble decompressing a huffman string back into the original string. I would appreciate any help on this. Please find attached my code so far. As you can see so far, I have most of it down, its just the decompression part that I need trouble with. Essentially, I need to rebuild a huffman tree using the huffman tree string and then use that …

Member Avatar
Member Avatar
+0 forum 1

This is a homework problem. I have 5 modules to encode and decode a txt file using the huffman algorithm along with. I'm having some difficulty with where to start with the decoding module. I have to do the decoding using the functions from binary.h and binary.cpp and my priority queues . Here is the code I have. //pqueue.h////// #include <iostream> #include <stdlib.h> #include "tree.h" using namespace std; typedef int PQPriorityType; struct PriorityQueue { int* ptr; PriorityQueue() { ptr = NULL; } }; void insert(PriorityQueue& q, PQItemType v, PQPriorityType priority); void remove(PriorityQueue& q, PQItemType &v, PQPriorityType &priority); void update(PriorityQueue& q, …

Member Avatar
+0 forum 0

Hi I am working on a project on writing our own huffman coding. I am currently having trouble writing the binary 1's and 0's to an output file. It works with smaller input files but for very large files it does not write anything out to the output file. The method responsible for writing is the `compress method`. Any help would be appreciated. Thank you! package proj3; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.Scanner; import java.util.PriorityQueue; public class Project3 { //variables for PriorityQueue and Huffman Tree private …

Member Avatar
Member Avatar
+0 forum 9

I am doing huffman coding and I have made the tree. Now I am required to traverse the tree to create bit strings associated with the characters. Then I will put the bit string and char into a map to use with encode/decode. I have been working on this for days and could really use some help. Thanks for any help you can offer! map<char, string> build_encoding_map(freq_info*& huffman_root) { map<char, string> ret; string char_code; char symbol; if (huffman_root->left == NULL && huffman_root->right == NULL) { cout << "Your tree is empty." << endl; } else { while (huffman_root->is_leaf = false) …

Member Avatar
Member Avatar
+0 forum 1

> My code Not working Why ???? there is some processor fault Error

Member Avatar
Member Avatar
+0 forum 2

Hello all, I'm having trouble writing a recursive algorithm to traverse a Huffman tree to encode a message. I'm sure you all know what they are. Here's my algorithm: string HuffmanCode(const char& symbol, const TreeNode<SymbolPriority>* huffman, string &code) { //Base case: you are in a leaf; if the leaf contains the character //you are looking for then return the code (third argument) //else return an empty string (which means ‘wrong leaf’). if(huffman->IsLeaf()) { if(huffman->Value.Symbol == symbol) return code; else return ""; } /*always start by going to the left and adding ‘0’ to the code (code + ‘0’); check the …

Member Avatar
Member Avatar
+0 forum 1

What are the settings I require so I can debug line -by line? Or else ,I can identify lines of code where run time errors are occuring.. I want to view exact line number of error in this code/[CODE]#include<stdio.h> #include<conio.h> #include<string.h> struct node {struct node * left,*right; int freq; char c; }; typedef struct node node; int front=1; node * q[256]; char * code[128]={0},array[1024]; node * new (int freq,char c,node * a ,node * b) { node * n=(node *)malloc(sizeof(node )); if(freq) {n->c=c; n->freq=freq;} else {n->left=a;n->right=b; n->freq=a->freq+b->freq; } return n; } void insert(node * n) {int i,j; i=front++; j=i/2; while((j=i/2)) …

Member Avatar
Member Avatar
+0 forum 3

[CODE]#define max 50 struct code{int bits[max];int start;};typedef struct code code; struct node{int freq;int father;int isleft;};typedef struct node node; void insert(int,int); int del(int); main() { code cd,code1[max]; node node1[max*2-1]; int i,k,n,p,p1,p2,root,rootnodes; char symb,alph[max]; for(i=0;i<max;i++) alph[i]=' '; rootnodes=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%s""%d",&symb,&node1[i].freq); insert(rootnodes,i); alph[i]=symb; } for(p=n;p<2*n-1;n++) { p1=del(rootnodes); p2=del(rootnodes); node1[p1].father=p; node1[p1].isleft=1; node1[p2].father=p; node1[p2].isleft=0; node1[p].freq=node1[p1].freq+node1[p2].freq; insert(rootnodes,p); } root=del(rootnodes); for(i=0;i<n;i++) { cd.start=max; p=i; while(p!=root) { cd.start-=1; if(node1[p].isleft) cd.bits[cd.start]; else cd.bits[cd.start]=1; p=node1[p].father; } for(k=cd.start;k<max;k++) {code1[i].bits[k]=cd.bits[k]; code1[i].start=cd.start; } for(i=0;i<n;i++) { printf("\n%c \t%d",alph[i],node1[i].freq); for(k=code1[i].start;k<max;k++) printf("%d",code1[i].bits[k]); printf("\n"); } } } [/CODE] This is an incomplete code for implementing a Huffman Code using priority queue. I have been given …

Member Avatar
Member Avatar
+0 forum 6

The End.