Click here to Skip to main content
15,891,248 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Huffman decoding from using two queues and cursors Pin
Stefan_Lang4-May-11 5:24
Stefan_Lang4-May-11 5:24 
GeneralRe: Huffman decoding from using two queues and cursors [modified] Pin
Francis Paran4-May-11 5:47
Francis Paran4-May-11 5:47 
AnswerRe: Huffman decoding from using two queues and cursors Pin
David Crow4-May-11 2:55
David Crow4-May-11 2:55 
GeneralRe: Huffman decoding from using two queues and cursors Pin
Francis Paran4-May-11 3:50
Francis Paran4-May-11 3:50 
QuestionRe: Huffman decoding from using two queues and cursors Pin
David Crow4-May-11 5:38
David Crow4-May-11 5:38 
AnswerRe: Huffman decoding from using two queues and cursors Pin
Francis Paran4-May-11 5:59
Francis Paran4-May-11 5:59 
GeneralRe: Huffman decoding from using two queues and cursors Pin
David Crow4-May-11 7:10
David Crow4-May-11 7:10 
GeneralRe: Huffman decoding from using two queues and cursors Pin
Francis Paran4-May-11 15:29
Francis Paran4-May-11 15:29 
Okay, I think I know now what I did wrong. It's the one that generates the Huffman tree before encoding the characters into their unique code, because I don't have the function to sort the nodes in the first queue after putting a new node that has the sum of the two smallest nodes in the first queue into the second queue (as another way of implementing besides a priority queue Huffman coding). Therefore, what happens is that 01 in a bit string will always print out 'e' in the decoding part. Below is the function that generates the two queue-cursor Huffman Coding Tree:

void generateHuffman (Queue& q1, Queue& q2)
{/*
   input - an initial sorted queue q1 of the frequencies of each character
   output - a sorted list q2 composed where every node is the sum of two 
            elements in q1 and has cursors in each one of these.
*/
QueueNode *leftChild, *rightChild, *tempNode;
char tempChar = q1.frontNode()->value;
 
q1.enqueueChar(tempChar, q1.dequeue());
q2.enqueue(q1.front()+q1.back());
rightChild = q1.backNode();
tempChar = q1.frontNode()->value;
q1.enqueueChar(tempChar, q1.dequeue());
leftChild = q1.backNode();
q2.setCursor(leftChild, rightChild);

while (q1.back() <= q1.front())
{/*
   @pre: q1 has all the elements sorted
   @post: all elements in q1 will be back in place with each of them referenced
          by elements in q2 */
	q2.enqueue( q1.front()+q2.front() );
	tempNode = q2.backNode();
	q2.enqueue(q2.dequeue());
	tempNode->rightCursor = q2.backNode();
	tempChar = q1.frontNode()->value;
	q1.enqueueChar(tempChar, q1.dequeue());
	tempNode->leftCursor = q1.backNode();
 
	while( q2.frontNode() != tempNode)
		q2.enqueue(q2.dequeue());
	tempNode = NULL;
}
 
}


I was trying to have a compare function for this, so that I can use the STL sort the way I did with the list of character frequencies in an array. What do you think. Is there any way that this can be better improved. Please help, thank you.
QuestionProcessing CStringW one char at a time Pin
csrss2-May-11 23:10
csrss2-May-11 23:10 
AnswerRe: Processing CStringW one char at a time Pin
csrss2-May-11 23:23
csrss2-May-11 23:23 
GeneralRe: Processing CStringW one char at a time Pin
Niklas L3-May-11 1:08
Niklas L3-May-11 1:08 
Questioncopy text on clipboard Pin
john56322-May-11 23:05
john56322-May-11 23:05 
AnswerRe: copy text on clipboard Pin
_AnsHUMAN_ 3-May-11 0:00
_AnsHUMAN_ 3-May-11 0:00 
GeneralRe: copy text on clipboard Pin
David Crow3-May-11 3:00
David Crow3-May-11 3:00 
AnswerRe: copy text on clipboard Pin
Hamid_RT3-May-11 0:57
Hamid_RT3-May-11 0:57 
QuestionHow can I find style of CListCtrl ? Pin
_Flaviu2-May-11 22:03
_Flaviu2-May-11 22:03 
AnswerRe: How can I find style of CListCtrl ? Pin
«_Superman_»2-May-11 22:10
professional«_Superman_»2-May-11 22:10 
GeneralRe: How can I find style of CListCtrl ? Pin
_Flaviu2-May-11 22:23
_Flaviu2-May-11 22:23 
GeneralRe: How can I find style of CListCtrl ? Pin
«_Superman_»2-May-11 22:26
professional«_Superman_»2-May-11 22:26 
GeneralRe: How can I find style of CListCtrl ? Pin
_Flaviu3-May-11 0:08
_Flaviu3-May-11 0:08 
GeneralRe: How can I find style of CListCtrl ? Pin
Niklas L3-May-11 2:42
Niklas L3-May-11 2:42 
AnswerRe: How can I find style of CListCtrl ? Pin
Hans Dietrich3-May-11 7:47
mentorHans Dietrich3-May-11 7:47 
QuestionC# ASP.NET TreeView control Pin
RalfPeter2-May-11 12:57
RalfPeter2-May-11 12:57 
AnswerRe: C# ASP.NET TreeView control Pin
Hans Dietrich2-May-11 15:23
mentorHans Dietrich2-May-11 15:23 
GeneralRe: C# ASP.NET TreeView control Pin
RalfPeter3-May-11 3:47
RalfPeter3-May-11 3:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.