hi, i was wondering if anyone had any examples of a Binary Search Tree written in C++?
thanks a lot
Name:
Anonymous2007-11-27 9:05
void btree::search()
{
// Enter code here
}
Name:
Anonymous2007-11-27 9:08
oh come on.. i'm in the first semester of my career :P and this is the final project
Name:
Anonymous2007-11-27 9:09
ah nvm i think that string kinda helped heheheeeeeeeeeee..
i will look in google for another hour..
Name:
Anonymous2007-11-27 9:09
Try figuring it out yourself instead of relying on others. They call that "learning".
Name:
Anonymous2007-11-27 9:12
void btree::search(int i)
{
if (i == this->i)
return true;
if (i < this->i && this->left)
return this->left->bsearch(i);
if (i > this->i && this->right)
return this->right->bsearch(i);
return false;
}
>>5
im a very good self learner BUT:
1. i don't reeeeeeeeeally have time right now
2. i got tired of googling all day
3. i didn't lose anything by asking, did i?
NOW, go out and ask a girl out, you won't lose anything! :p
back to business
>>6
thanks, those are the things i need... small pointers to guide me to the right direction
You did lose something by asking. You failed to understand the problem, you failed to find a solution for the problem and you failed to implement and test the solution by yourself.
If you're going to have other people do things for you, you might as well drop out of school right now.
Asking out girls is not the same, because learning to interpret their behavior and becoming experienced in talking to girls actually requires you to ask them questions.
Name:
Anonymous2007-11-27 9:30
def search_binary_tree(node, key):
if node is None:
return None # key not found
if key < node.key:
return search_binary_tree(node.left, key)
else if key > node.key:
return search_binary_tree(node.right, key)
else: # key is equal to node key
return node.value # found key
>>13
Nah, im actually one of the best in my career right now, but i hate programming :-/
And LOL nice response.... But if you analyze the concept of asking out a girl, you will find out that NAAAAAAAAHH im not gonna continue that hehe im not the kind of fight starter
nice..... i find genealogical trees as examples for binary search trees everywhere.. is there any difference between that and a normal, generic binary tree??
thanks everyone for their help, i think i'm heading in a better way right now
Name:
Anonymous2007-11-27 9:53
>>16
Nah, im actually one of the worst in my career right now, but i read SICP :-/
And LOL nice response.... But if you analyze the concept of asking out a Lisp Wizard, you will find out that NAAAAAAAAHH im not gonna continue that hehe im not the kind of fight starter
nice..... i find gynecological trees as examples for binary search trees everywhere.. is there any difference between that and a normal, geriatric binary tree??
eeeerrrrrrrr i repeat, i AM falling asleep LOL god... what am i thinking
Name:
Anonymous2007-11-27 10:13
Damn it, man - are you retarded?
Also, binary search trees are entirely the wrong data structure to store ancestral relationships.
Name:
Anonymous2007-11-27 10:14
>>23
no, im not retarded... i just have NEVER programmed before, i barely know C++
"Also, binary search trees are entirely the wrong data structure to store ancestral relationships."
really? damn.. well, what do you recommend? linked lists? queues?
binary trees seemed just perfect to me :-/
Name:
Anonymous2007-11-27 10:33
>>24
Binary search trees are excellent when you have a list of items that you need to search quickly, but by design has several features that make it inappropriate for your application. Most importantly, each node only has two children and they are ordered such that the left_node < parent_node < right_node.
When designing your data structure, think about your constraints. Each node (person) has up to two known parents (unless you count adoptive parents, then maybe more), and may have zero or more children. Also, the structure may not strictly be a tree as incestuous relationships can occur that cross generational boundaries.
You should consider how your data will be used, as it will help determine how much redundant/pre-calculated/process data you wish to store to speed things up.
(Of course, you can use a binary search tree if you wanted to index a particular piece of information such as surname or date of death. But the information you want to store doesn't fit that data structure alone.)
>>25
lol wut ______child______
| |
_____mom_____ _____dad_____
| | | |
mom___ ___dad mom___ ___dad
| | | | | | | |
mom dad mom dad mom dad mom dad
How the fuck is this not a binary tree?
inb4 YHBT. YHL. HAND.
Name:
Anonymous2007-11-27 11:06
>>27
______child______
| |
_____mom_____ _____dad_____
| | | |
mom___ ___dad mom___ ___dad___
| | | | | | | | |
mom dad mom dad mom dad mom dad mom
NOW WHAT
Name:
Anonymous2007-11-27 11:07
>>27
You fail it, HARD. Firstly, you obviously don't know the difference between a binary search tree (as was the subject of the OP's question) and a binary tree. And most importantly - your data structure is only suitable if each couple has only one child.
The time you wasted with your shitty ASCII art would have been better spent educating yourself on computer science fundamentals.
Name:
Anonymous2007-11-27 11:07
>>27
mmm that's exactly what i was thinking of in the first place :/
>>29
Yeah, he asked for a binary search tree. But what does that mean in the context of a genealogy? Or a genealogical tree? How do you define a total order for the set of all ancestors of a given person?
It's a stupid question. A binary search tree isn't the right structure. A person's entire ancestry (omitting anomalies and complications as shown in >>33) can be represented as a single simple binary tree.
As for your comment about my tree only showing a single child - durr, your brother/uncle/second-cousin-once-removed didn't contribute to your genetic makeup - they're not in your ancestral tree.
If you'd like to criticize my confusion of an ancestral tree with a genealogical tree (if they're not the same thing), then feel free to do so. Otherwise, you're a dickhead.
mmmmm well i got confused because many websites trying to explain the concept of binary trees explain them with numbers, and when they get to the binary search tree.. they use examples with people's names...
that's why i thought it would be the best choice for a genealogical tree...
You're a unifag who can't google or figure out binary trees. We're superior to you in every way.
Read SICP.
Name:
Anonymous2007-11-27 20:09
>>37
You would probably want to use a directed graph to implement this, due to the aforementioned reasons mentioned above (incestuous relationships and what not)
Name:
Anonymous2007-11-27 23:06
>>35
From the information he has given, it's clear that he wants a data structure that can hold the relations between different family members of different generations, not just the subset of that that is all the parents, grandparents, great-grandparents, etc. of a particular child.