Click here to Skip to main content
15,919,567 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Check Internet speed Pin
ThatsAlok6-Apr-08 22:50
ThatsAlok6-Apr-08 22:50 
GeneralCComMultiThreadModelNoCS Pin
George_George6-Apr-08 19:53
George_George6-Apr-08 19:53 
QuestionATL bug of CComPtr? Pin
George_George6-Apr-08 19:42
George_George6-Apr-08 19:42 
AnswerRe: ATL bug of CComPtr? Pin
CPallini6-Apr-08 22:14
mveCPallini6-Apr-08 22:14 
GeneralRe: ATL bug of CComPtr? Pin
George_George6-Apr-08 22:26
George_George6-Apr-08 22:26 
GeneralRe: ATL bug of CComPtr? Pin
CPallini6-Apr-08 23:09
mveCPallini6-Apr-08 23:09 
GeneralRe: ATL bug of CComPtr? Pin
George_George6-Apr-08 23:12
George_George6-Apr-08 23:12 
QuestionProblem with Binary Tree Program [modified] Pin
Member 42588976-Apr-08 17:58
Member 42588976-Apr-08 17:58 
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>
GeneralRe: Problem with Binary Tree Program Pin
Member 42588978-Apr-08 16:32
Member 42588978-Apr-08 16:32 
Questionhow to spy++ a windows which will hide when it lose focus? Pin
code_discuss6-Apr-08 17:24
code_discuss6-Apr-08 17:24 
GeneralRe: how to spy++ a windows which will hide when it lose focus? Pin
CPallini6-Apr-08 21:35
mveCPallini6-Apr-08 21:35 
GeneralRe: how to spy++ a windows which will hide when it lose focus? Pin
code_discuss6-Apr-08 21:55
code_discuss6-Apr-08 21:55 
GeneralCStdioFile problem Pin
lisoft6-Apr-08 16:24
lisoft6-Apr-08 16:24 
GeneralRe: CStdioFile problem Pin
nisha000006-Apr-08 18:11
nisha000006-Apr-08 18:11 
GeneralRe: CStdioFile problem Pin
lisoft6-Apr-08 18:47
lisoft6-Apr-08 18:47 
GeneralRe: CStdioFile problem Pin
nisha000006-Apr-08 19:40
nisha000006-Apr-08 19:40 
GeneralRe: CStdioFile problem Pin
krmed7-Apr-08 1:50
krmed7-Apr-08 1:50 
GeneralRe: CStdioFile problem Pin
lisoft7-Apr-08 15:18
lisoft7-Apr-08 15:18 
GeneralRe: CStdioFile problem Pin
krmed8-Apr-08 0:47
krmed8-Apr-08 0:47 
GeneralRe: CStdioFile problem Pin
Hamid_RT8-Apr-08 7:21
Hamid_RT8-Apr-08 7:21 
GeneralOn implementing a virtual keyboard Pin
Llasus6-Apr-08 16:10
Llasus6-Apr-08 16:10 
QuestionWhere Does a static attribute reside in a Object ?? Pin
ForNow6-Apr-08 15:57
ForNow6-Apr-08 15:57 
AnswerRe: Where Does a static attribute reside in a Object ?? Pin
Dan6-Apr-08 17:53
Dan6-Apr-08 17:53 
GeneralRe: Where Does a static attribute reside in a Object ?? Pin
ForNow7-Apr-08 15:52
ForNow7-Apr-08 15:52 
GeneralFile Access Privileges Pin
Richard Andrew x646-Apr-08 15:56
professionalRichard Andrew x646-Apr-08 15:56 

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.