|
Francis Paran wrote: The thing is that every bit string representation of a character always ends up with a '1'. Whenever '1' is found in the string, the program should print out leftCursor->value of...
Hence my suggestion to step through the code using the debugger.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
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)
{
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())
{
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.
|
|
|
|
|
How would i iterate over CStringW characters?
I need the equivalent of this:
void func(wchar_t *Stuff)
{
int len = wcslen(Stuff);
for(int i = 0; i < len; i++)
{
std::wcout << Stuff[i] << std::endl;
}
}
Thanks.
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
Alright, solved it.
for(int i = 0; ; i++)
{
wchar_t ch = pString.GetAt(i);
if(ch == 0) break;
}
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
operator[] is defined for CString, (CStringW and CStringA), so there should be no problem using that either.
|
|
|
|
|
Hi,
How can I copy text on clipboard?
|
|
|
|
|
Are you using MFC? If affirmative see the SetClipboardData[^] API
You talk about Being HUMAN. I have it in my name
AnsHUMAN
|
|
|
|
|
_AnsHUMAN_ wrote: Are you using MFC? If affirmative see the SetClipboardData[^] API
With SetClipboardData() , it matters not if MFC is being used.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
|
I need to know , for CListCtrlEx::OnNMCustomdraw(...) if list control have LVS_EX_FULLROWSELECT AND LVS_EX_GRIDLINES extended style ... my question is , there is a method to find that in single line of code ? I try this :
GetExtendedStyle() & LVS_EX_FULLROWSELECT & LVS_EX_GRIDLINES
but is stupid .
And one more thing : it's a good ideea to check that ( have 2 extended style ) in OnNMCustomdraw(...) in above style ? Or it be good thing to set up a variable that know if list control have both extended style ?
Thnak you .
|
|
|
|
|
You can check this as follows - if ((GetExtendedStyle() & LVS_EX_FULLROWSELECT) && (GetExtendedStyle() & LVS_EX_GRIDLINES))
If you want to assign it to a variable, you could do this -
bool bHasBothStyles = ((GetExtendedStyle() & LVS_EX_FULLROWSELECT) && (GetExtendedStyle() & LVS_EX_GRIDLINES));
bool bHasOneStyle = ((GetExtendedStyle() & LVS_EX_FULLROWSELECT) || (GetExtendedStyle() & LVS_EX_GRIDLINES));
|
|
|
|
|
Thank you for answer , I will do in this way . I try do to a fast code for NMCustomDraw(...).
|
|
|
|
|
Even though it works in one line, you should assign the return value of GetExtendedStyle() to a variable and then use the variable instead of calling GetExtendedStyle twice.
|
|
|
|
|
You are right . Thank you .
|
|
|
|
|
If checking for multiple flags, it might be easier to do it like this:
DWORD styles = (LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
bool bHasAllStyles = (GetExtendedStyle() & styles) == styles;
|
|
|
|
|
Don't forget that it is possible to set the CListCtrl style after it has been created. So to be safe, you should check the style right before you need to use it, rather than store it in a variable only once.
|
|
|
|
|
Hi all,
I am trying to find out how to check the 'check' state of a node in a TreeView control using C# in an ASP.NET application. Basically, I have a TreeView control that shows checkboxes. The user makes a selection which I want to store in a session variable upon a 'submit' button click. I use a 'TreeView.Node.Checked' statement to verify whether the user selected that node. This, however, does not work because the selection is made at the client side and when it gets posted to the server, the 'TreeView.Node.Checked' statement, whether selected or not, will always return 'false' for any node. Does anyone have a solution for this? Thx,
Ralf
ralf.riedel@usm.edu
|
|
|
|
|
|
Will do. Thx,
Ralf
ralf.riedel@usm.edu
|
|
|
|
|
Is it possible for a void function that outputs characters using the cout<< extraction statement be able to put its results into a specific file via an ofstream variable, and if yes then what function should I use?
The function works this way:
void encode(QueueNode *ithNode, char charKey)
{
if (ithNode->rightCursor != NULL)
{ if (ithNode->leftCursor->value == charKey)
cout<<"1";
else
{
cout<<"0";
encode(ithNode->rightCursor,charKey);
}
}
else
cout<<"1";
}
Basically, it outputs a binary string representation of a character. What I want to do now is to transfer each of these output bits into a file with a use of an ofstream function. Any ideas on how to do this?
|
|
|
|
|
You could rewrite the function to take the ostream as an argument
void encode(QueueNode *ithNode, char charKey, ostream &os)
{
if (ithNode->rightCursor != NULL)
{ if (ithNode->leftCursor->value == charKey)
os<<"1";
else
{
os<<"0";
encode(ithNode->rightCursor,charKey, os);
}
}
else
os<<"1";
}
And call it
ofstream ofs("data.dat");
encode(..., ..., ofs);
encode(..., ..., cout);
|
|
|
|
|
Got it, thanks for the advice.
|
|
|
|
|
hi
can i make the folder which of default to any file type ...
i had idea that if possible to convert the directory to a file format which have the unique extension so that when double clicked it will ask the password ...
actually i am doing the project on the folder security
|
|
|
|
|
If you are just wanting to set security permissions on a folder, see here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
That's pretty much how the tar format works, or any other bundling format, like zip and rar , for that matter. There's a lot of information on this if you search for it.
|
|
|
|