473,883 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BTree beginner

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",E ND},
{END,"AD",END},
{4,"Son",END},
{END,"QS",END}} ;
string skey;
int it=0;
std::cout<<"sea rch = ";
std::cin>>skey;
while(it!=END){
if((name[p].str).compare(k ey)==0){
std::cout<<"fou nd it\n";
break;
}
else if((name[p].str).compare(k ey)<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
Jul 23 '05 #1
4 2193
Hello!
First of all, is your code imply that Parent>Daugther >Son>QC?
Dear man how come?
If you fix this all will be easy and I think this is sorted binary tree
right?
Edernity
-----------
THESE ARE FROM MY PREVIOUS POST. I just wanna say this last time.
Mercy, Mercy for one without one will be condemn and damn ...ops darn
by God
and that right give up may god darn on you really. unless u help
JASON.really darn........and out of this darn I'm to avoid condemn
ALRIGHT I'M GIVING ALL THAT ALREADY READ THIS A CHANCE (THIS NG),
pls help. If my posting is useless I'll go. Remeber that God hate
miser.
if it help (IT DON'T CAUSE YOU A CENT. JUST 1 EMAIL THEN FILLING FORMS)
please do help me provide better school supplies for childrenof
indonesia.
IN FACT, for those other who already read this plea and maybe finding
my post helpful, what is I give you one dollars for it. I don't believe
this, I'm paying to get people to donate to kids?!!!???that really
ugly!
it may be a donation but I merely ask you to letme send email to you
from one of the product of I'm affiliated and please register there on
mechant account free. If you even want you refund back on your dollar
of i-kard, its ok, I'll send you just use regular delivery on shipping
please. Please note this is very safe since this is a bonafid company.
remember your credit card company will confirm you on your purchase.
u can add or remove more credit cards into your account. you can/should
also ask for always confirmation on send out to you. That will get
those savage cracker bloke out. even u can use some more free teen
refillable visa/mastercard from your bank cc account (can be obtaion
free).
It is just unnerving seeing how can people do not do anything as so
they need so little. $10 could support {{{{{the child 1 month.}}}}
Still have doubts, sign on a personal account and let me contact you
again on it. just one mail pls
also
I'm also affiliated to this site:
www.getaportal.com/portals/edd y_ruslim
Unless u wanto e-gold it at 1369872
New to egold:www.e-gold.com/e-gold.asp?cid= 1369872
NAH, previous way cost u zilch
God bless

Jul 23 '05 #2
"Edernity" <ed*********@te lkom.net> wrote in message news:<11******* *************** @g14g2000cwa.go oglegroups.com> ...
Hello!
First of all, is your code imply that Parent>Daugther >Son>QC?
Dear man how come?
If you fix this all will be easy and I think this is sorted binary tree
right?
Edernity

Yes, thats a simple sorted Btree, I only need help with that.. Could
you tell me something about that ? way to search it better and gives
me correct results ??

[snip]
THESE ARE FROM MY PREVIOUS POST. I just wanna say this last time.
Mercy, Mercy for one without one will be condemn and damn ...ops darn
*********** *************** *************** ***********<<<<

also ask for always confirmation on send out to you. That will get
those savage cracker bloke out. even u can use some more free teen[/snip]


Your signature is long!
Jul 23 '05 #3
Spam Me Please wrote:
I have a tree like this
// Include the standard headers for streams and strings.
#include <iostream>
#include <string>

// Import some things into the current namespace.
using std::cin;
using std::cout;
using std::string;

struct BTree
{
int left;

// Your later code references a string called str, not an
// array called c.

//char c[1];
string str;

int right;
};

#define END -1

int main( int argc, char* argv[ ] )
{

// This tree cannot be searched in the way you think, because
// the keys have not been inserted according to lexicographical
// comparisons of the strings. For example, you have "Daughter"
// and "AD" on opposite sides of "Parents," but they are both
// before it lexicographical ly.

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 )
{
// You never declared "p". Did you mean "it"?
// You never declared "key". Did you mean "skey"?

//if( ( name[ p ].str ).compare( key ) == 0 )
if( name[ it ].str == skey )
{
std::cout<<"fou nd it\n";
break;
}
//else if((name[p].str).compare(k ey)<0)
else if( name[ it ].str < skey )
{
// p=name[p].right;
it = name[ it ].right;
}
else
{
//p=name[p].left;
it = name[ it ].left;
}
}

// You won't need to do this if you learn to use a command line.
// I recommend the "bash" shell, available for Windows using
// Cygwin.
// 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 ?


Your search incorrectly assumes that the tree is sorted, so it never
finds the search key.

The traditional way to search a tree is using recursion. I actually
prefer looping, but recursion can be much simpler (and therefore easier
to do correctly). Search trees can be tricky to implement without
pointers and recursion... Was this actually assigned to you by a
professor? It seems a little sadistic.
Jul 23 '05 #4
Spam Me Please wrote:

I can't search Son and QS and AD, why ????
Take a piece of paper and start painting your tree
struct BTree name[5]={{1,"Parents", 2},
{3,"Daughter",E ND},
{END,"AD",END},
{4,"Son",END},
{END,"QS",END}} ;

0: "Parents
left: 1 right: 2

/ \
/ \
1: "Daughter" 2: "AD"
left: 3 right: END left: END right: END

/
/
3:"Son"
left: 4 right: END

/
/
4: "QS"
left: END right: END
Now look at this tree. The way the search function is coded, it assumes that
for every node, the right childnode is 'less' then the currect node. Compare
with your tree. Look at every node. Is it tree that for every node, the left
childnode is 'less' then the node? No. Eg. node 1: "Daughter". It has a left
childnode of "Son". But "Son" is not less then "Daughter". Same for "Parent"
and "AD".

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1264
by: Jane Austine | last post by:
Hello. How do I change the BTree sorting order with bsddb, instead of the default lexicographical order? After studying sleepycat's document, I found there is a function call for setting the compare callback, set_bt_compare. It even seems like got into pybsddb patch list (http://sourceforge.net/tracker/index.php?func=detail&aid=532308&group_id=13900&atid=313900). However, the current Python source tree (cvs) doesn't include the patch.
5
2068
by: Nobody | last post by:
I am trying to write a BTree class, just wondering if I missed any useful methods. This is my class definition so far (excuse the MFC portions, its a project requirement): template <class TYPE, class ARG_TYPE = const TYPE&> class CBTree : public CObject {
4
5254
by: Eloff | last post by:
I've got 100MB of urls organized by domain and then by document. I thought that a hastable of hastables or a btree of btrees would be a good way to lookup a specific url quickly by first finding the domain and then finding the matching document. What do you think would be better? And do you have any implementation you recommend? Thanks, and merry Christmas folks. -Dan
2
2573
by: Mark Harrison | last post by:
I create a table like so: create table types ( typeid integer unique not null, typename varchar(255) unique not null ); and I get the expected messages: NOTICE: CREATE TABLE / UNIQUE will create implicit index 'types_typeid_key' for table 'types'
4
3121
by: os2 | last post by:
hi i would like to catalog my hd and put the data in a btree somebody know how to do it? a hint to begin? thanks
1
3142
by: Brian Maguire | last post by:
Can too many btree indexes cause page level locking? I read this... http://www.postgresql.org/docs/7.4/static/locking-indexes.html
0
2256
by: Rano | last post by:
Hi could u guys look at this assignment sheet and try to help me to display the Btree in this form by using x and y coordinate plzzzzzzz help 10 3 11 2 4
0
1295
by: sudhi nair | last post by:
hi dba's i want an automated script for converting btree index (with less cardinality) to bitmap index bcoz old version is 10g std edition now migration to 10g enterp edition any body know pls post regads
22
18160
by: ddg_linux | last post by:
I have been reading about and doing a lot of php code examples from books but now I find myself wanting to do something practical with some of the skills that I have learned. I am a beginner php programmer and looking for a starting point in regards to practical projects to work on. What are some projects that beginner programmers usually start with? Please list a few that would be good for a beginner PHP programmer to
0
9948
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9798
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11164
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10422
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7137
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5807
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6008
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4623
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4230
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.