G
Guest
I have a tree like this
struct BTree{
int left;
char c[1];
int right;
};
#define END -1
int main(int argc, char *argv[])
{
struct BTree name[5]={{1,"Parents",2},
{3,"Daughter",END},
{END,"AD",END},
{4,"Son",END},
{END,"QS",END}};
string skey;
int it=0;
std::cout<<"search = ";
std::cin>>skey;
while(it!=END){
if((name[p].str).compare(key)==0){
std::cout<<"found it\n";
break;
}
else if((name[p].str).compare(key)<0)
p=name[p].right;
else
p=name[p].left;
}
system("PAUSE");
return 0;
}
I can't search Son and QS and AD, why ????
Do you know how search a my struct above without using loop as my
source code shows ?
Thank you
Jason
struct BTree{
int left;
char c[1];
int right;
};
#define END -1
int main(int argc, char *argv[])
{
struct BTree name[5]={{1,"Parents",2},
{3,"Daughter",END},
{END,"AD",END},
{4,"Son",END},
{END,"QS",END}};
string skey;
int it=0;
std::cout<<"search = ";
std::cin>>skey;
while(it!=END){
if((name[p].str).compare(key)==0){
std::cout<<"found it\n";
break;
}
else if((name[p].str).compare(key)<0)
p=name[p].right;
else
p=name[p].left;
}
system("PAUSE");
return 0;
}
I can't search Son and QS and AD, why ????
Do you know how search a my struct above without using loop as my
source code shows ?
Thank you
Jason