|
In my program, I pick a pivot p from a database S of strings, compute the median r of the distances of other string objects to p and then divide the other objects into roughly equal-sized subsets S1 and S2 as follows:
<pre>
S1={o e S \{p}|d(p,o)<r}
S2={o e S \{p}|d(p,o)>=r}
</pre>
where d(p,o) is the distance of the database object o to pivot p.Thus, the objects in S1 are inside the ball of radius r around p, while the objects in S2 are outside this ball. Applying this rule recursively leads to a binary tree,where a pivot object is stored in each internal node, with the left and right subtrees corresponding to the subsets inside and outside the corresponding ball,respectively.
Below I give the function for the above criteria but when I call the function from main and try to print the tree in preorder, nothing gets printed nor does the program terminate. I will really appreciate if someone can help me find the errors in my code and where I am going wrong:
<pre>
void query_ball()
{
string str;
int i=0,p;
int arr[1000];
char B[40];
char C[40];
vector<string> myStrings(1000);
int r;
int n1;
ifstream file("text.txt"); //this file is the database containing 1000 strings
for(p=0;p<1000;p++)
{
getline(file,str);
strcpy(B,str.c_str());
myStrings[p]=B; // copying the file strings to vector myStrings
}
srand(time(0));
int pos;
pos=rand()%1000;
strcpy(C,myStrings[pos].c_str()); // C is the pivot picked randomly
for(i=pos;i<=998;i++) // deleting element at myStrings[pos] which contains pivot C
myStrings[i]=myStrings[i+1];
myStrings[i]="";
for(p=0;p<999;p++)
{
strcpy(B,myStrings[p].c_str());
arr[p]=edit(B,C); // arr contains edit distances between other string objects and pivot C
}
/*edit function relates to edit distances of pivot from other string objects. An edit distance between 2 strings is found by changing one string to another with the minimum number of insertions, deletions and/or replacement of characters in the strings.*/
n1=(999+1)/2;
r=arr[n1]; // r is the median of the distances of other objects to pivot C
for (p=-1; p<999; p++) //p starts with -1 to check first if Root is Null
{
if (Root == NULL)
{
Root = new TreeNode();
Root->val = C;
}
else
{
TreeNode* temp = Root;
while(temp!=NULL)
{ strcpy(B,myStrings[p].c_str());
if (edit(B,C)<r) // checking distances inside ball of radius r
{
if (temp->LChild==NULL)
{ TreeNode* t = new TreeNode();
t->val = B;
temp->LChild=t;
}
else
{
TreeNode* t = new TreeNode();
t->val = B;
temp->LChild = temp->LChild->t;
}
}
if (edit(B,C)>=r) // checking distances outside ball of radius r
{
if (temp->RChild==NULL)
{ TreeNode* t = new TreeNode();
t->val = B;
temp->RChild=t;
}
else
{
TreeNode* t = new TreeNode();
t->val = B;
temp->RChild = temp->RChild->t;
}
}
}
}
}
}
</pre>
<div class="ForumMod">modified on Monday, April 7, 2008 12:18 AM</div>
|
|
|
|
|
Referring to the above codes, I see that when I print the children of the left tree, it gives me segmentation fault. Can somebody please point out why I am getting segmentation fault for the cout statement in the codes below:
if (edit(B,C)<r)>
{
if (temp->LCh==NULL)
{
t1->val = B;
temp->LCh=t1;
}
else
{
TreeNode* t = new TreeNode();
t->val = B;
temp->LCh=temp->LCh->t;
cout<<temp->LCh->val<<endl;
}
}
</r)>
Any help much appreciated.
|
|
|
|
|
I'd like to use spy++ to watch on a window, but that window will hide automatically when it lose focus, which means it will hide as soon as I lauch/switch to spy++.
So how can I do that?
|
|
|
|
|
Actually Spy++ shows hidden windows too.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Yes I know.
But now it's difficult for me to find that window using spy++.
The windows appears to be hidden, but it may already be destroyed. If it's destroyed when losing focus, I can't find it using spy++.
But I really want to find that window and find its class name, window text, ect, which info I can use to find them by code.
So.. Please help me out.
|
|
|
|
|
Hi all: I've got problem with CStdioFile::Open and need your help, below is the code sample:
<br />
CString m_filename="some absolute file path\name";<br />
CStdioFile m_file;<br />
if (!m_file.Open(m_filename,CFile::modeCreate|CFile::modeWrite))<br />
{<br />
AfxMesageBox (_T("Can not open the file"));<br />
}<br />
I'm sure the absolute file path/name is correct and have read/write permission to the file location.
When I run this code from Visual Studio by press CTRL+F5, this code is OK and the file is opened sucessfully. But when running the program out of the studio, I got problem that get into the AfxMesageBox showing the file can not be open.
Lisoft
|
|
|
|
|
CString m_filename="some absolute file path\name";
CStdioFile m_file;
if (!m_file.fOpen(m_filename,CFile::modeCreate|CFile::modeWrite))
{
AfxMesageBox (_T("Can not open the file"));
}
Try this..
Actually CstdioFile used for creating file in runtime so u ll modify above ..
|
|
|
|
|
You mean replace m_file.Open() with m_file.fOpen()? What is fOpen?
Lisoft
|
|
|
|
|
its just try ..if it is that create run time u may be add fopen
|
|
|
|
|
The way you show your m_filename is not an absolute path, but a relative path.
When you run from within VS (Ctrl_F5) the default working directory is the same folder as your .sln/.vcproj file. Let's say it's "MyProg", thefore you would attempt to open the file in VS, the path would be
MyProg\some absolute file path\name However, if you run it from the Windows Explorer (double click on it) the default directory would be the location of the .exe. In this case, it might be
MyProg\debug\some absolute file path\name The CStdioFile.Open will not create directories if the don't exist, and that would cause it to fail.
Perhaps if you show the actual contents of your m_filename it may be helpful.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Thanks for your help, but I'm always looking into the m_filename and I'm sure that was absolute. Something newly found today that when I call m_file.Open() I got an warnning message:Warning: could not get volume information 'd:\Documents and Settings\mmn7xxl\My Documents\My Project\Program\WareHouseReport\"d:\' . Can you figure this out for me?
Lisoft
|
|
|
|
|
That string can't really be a file name.
lisoft wrote: d:\Documents and Settings\mmn7xxl\My Documents\My Project\Program\WareHouseReport\"d:\
Show the actual code where you build that string and maybe we can help.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Maybe you have this file, can you show path?
|
|
|
|
|
Hello and good day!
I want to implement a virtual keyboard for my project. Although the Windows XP already provides one for use, I need the buttons and font to be bigger in size. I'm thinking of currently creating my own virtual keyboard but I want to make sure first if there would be other ways available. Should I create one or are there any other easier methods that I can use? If you say that I should create one, giving me pointers on what is needed would be a great help (currently reading SendInput function). Please note that what I'm gonna implement is a japanese keyboard and buying software is not an option.
Thank you for the help and time!
|
|
|
|
|
Hi,
As MainFramer I knowing that knowing Assembler always helped understand concepts
Anyway to the point I wrote some inline _asm code in a Method
In order to access the data in the Class I realized that the "this"
pointer (pointer to the object) resides on the stack after
paramter variables
I also relized when trying to initilize data with static that I had
to do it in the program
Why ??? the storage for static attribue members do not reside in the
Object rather in the program
This point was further driven home in my _asm code I tried to
access the data the way it was documented on the MSDN page
following is the the code from the MSDN web page
InlineAssembler_Accessing_C_asm_Blocks.cpp
// processor: x86
#include <stdio.h>
struct first_type
{
char *weasel;
int same_name;
};
struct second_type
{
int wonton;
long same_name;
};
int main()
{
struct first_type hal;
struct second_type oat;
__asm
{
lea ebx, hal
mov ecx, [ebx]hal.same_name ; Must use 'hal'
mov esi, [ebx].weasel ; Can omit 'hal'
}
return 0;
I used the following code to access the data in a my Class
First a example of my class
class MYClass
{
private:
static char *c;
static int d;
public:
.
.
.
etc
Now My _asm code
void MYClass :: class(int a, int b)
{
_asm
{
mov ebx,DWORD PTR 16[ebp] ; get this pointer
lea esi,[ebx].d
I got a compile/assemble error when "d" os declared as static
: error C2411: 'd' : illegal struct/union member in 'second operand'
Makes sense becuase when d is declared as static the storage doesn't
reside in the Object
So Whats my question ????
If I use the static attribute how can I access it in _asm code
Thankx
|
|
|
|
|
I have had this problem before, I just cheated.
int *dPtr = &d;
then u can just lea the dPtr value.
|
|
|
|
|
I got error LNK2001 When I tried that I didn't Lea since the pointer had the address all I had to do was a mov instruction
|
|
|
|
|
I'm creating a backup program, and I need to be able to open files with the ACCESS_SYSTEM_SECURITY privilege.
However, when I specify this privilege in my call to CreateFile, it tells me I'm missing a "required privilege" even when I run it as Admin.
This is on Vista.
What are the steps for getting the required privilege to open files with this access right?
“Cannot find REALITY.SYS...Universe Halted.”
~ God on phone with Microsoft Customer Support
|
|
|
|
|
hi
i have created adialog based application.but i just found out recently that it is hard to link a database to adialog("such as displaying results in an edit box ")
Is it really that difficult??
and can some one tell me how to do it???
please i really need it ("its for my project and i will reach my time limit soon ")
please >>>any help will be appreciated.
thank u in advance
Lahom
|
|
|
|
|
Did you search on the codeproject?
|
|
|
|
|
Hi,
I wanna know how could i drew a few cercles just by typing with lines of code. I'm under MFC on MSVS 6.0. is there some struct that could help me to drew such shapes?
hope that i wrote right
And thank you.
"The Ultimate Limit Is Only Your Imagination."
modified on Sunday, April 6, 2008 4:21 PM
|
|
|
|
|
Do you mean something like this?
void CMyWnd::OnPaint()
{
CPaintDC dc(this);
dc.Ellipse(10, 10, 50, 50);
}
Or do you want to write the circle drawing code yourself? If so, Google "circle drawing algorithm".
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Ok so let's say that i wanna drew 3 cercles on my formview, so shoulf i write that code 3 times with different values?
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
did ever heard about loops?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
CPallini wrote: did ever heard about loops?
These?[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|