Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Binary Search Tree in C++

Name: Anonymous 2007-11-27 9:02

hi, i was wondering if anyone had any examples of a Binary Search Tree written in C++?

thanks a lot

Name: Anonymous 2007-11-27 9:05

void btree::search()
{
    // Enter code here
}

Name: Anonymous 2007-11-27 9:08

oh come on.. i'm in the first semester of my career :P and this is the final project

Name: Anonymous 2007-11-27 9:09

ah nvm i think that string kinda helped heheheeeeeeeeeee..

i will look in google for another hour..

Name: Anonymous 2007-11-27 9:09

Try figuring it out yourself instead of relying on others. They call that "learning".

Name: Anonymous 2007-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;
}

Name: Anonymous 2007-11-27 9:15

gb2/school/

Name: Anonymous 2007-11-27 9:18

>>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

>>7
LOL i AM in school right now

Name: Anonymous 2007-11-27 9:22

oh and if i wanted everything solved, i would have said HEY, MAKE ME A PROGRAM TO BE ABLE TO SHOW A GENEALOGIC TREE

the true assignment was to program a genealogic tree, i thought it was a good idea to make it through binary search trees

any recommendations on that?

Name: sage 2007-11-27 9:24

genealogical*** (i think)

sorry for the grammar, i am foreign hehe

Name: Anonymous 2007-11-27 9:25

i am also falling asleep.. forgot sage goes in the e-mail field...

Name: Anonymous 2007-11-27 9:25

>>9
std::set.

You're not fucking using C. Stop re-inventing the goddamn wheel.

Name: Anonymous 2007-11-27 9:29

>>8

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: Anonymous 2007-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

Name: Anonymous 2007-11-27 9:38

OP, you're a fucking moron.

Kill yourself.

Name: Anonymous 2007-11-27 9:45

>>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

but yeah...

hey, class is almost over

>>14

nice.....    i find genealogical trees as examples for binary search trees everywhere.. is there any difference between that and a normal, generic binary tree??

Name: Anonymous 2007-11-27 9:46

>>15
out of context!   and.. nah, i'm awesome... i enjoy life

Name: Anonymous 2007-11-27 9:49

>>16
Wow, you're a moron and a virgin. Welcome to /prog/

Name: Anonymous 2007-11-27 9:51

alright, class is over...

thanks everyone for their help, i think i'm heading in a better way right now

Name: Anonymous 2007-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

but yeah...

hey, class is almost satori

>>14

nice.....    i find gynecological trees as examples for binary search trees everywhere.. is there any difference between that and a normal, geriatric binary tree??

Name: Anonymous 2007-11-27 9:59

>>20
"Let me help you into the stirrups..."

kekeke

Name: Anonymous 2007-11-27 10:07

"i find gynecological trees"

eeeerrrrrrrr i repeat, i AM falling asleep LOL god... what am i thinking

Name: Anonymous 2007-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: Anonymous 2007-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: Anonymous 2007-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.)

Name: Anonymous 2007-11-27 10:35

>>25
i see...

a MILLION thanks dude

Name: Anonymous 2007-11-27 10:57

>>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: Anonymous 2007-11-27 11:06

>>27

         ______child______
        |                 |
  _____mom_____     _____dad_____
 |             |   |             |
mom___     ___dad mom___     ___dad___
 |    |   |    |   |    |   |    |    |
mom  dad mom  dad mom  dad mom  dad  mom

NOW WHAT

Name: Anonymous 2007-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: Anonymous 2007-11-27 11:07

>>27
mmm that's exactly what i was thinking of in the first place :/

Name: Anonymous 2007-11-27 11:08

>>28
in b4 3some

Name: Anonymous 2007-11-27 11:59

/prog/ needs a BAN HAMMER for shitfuckers who can't fucking code.  We're not your teacher, faggots.

Name: Anonymous 2007-11-27 13:04

>>31

         ______child______
        |                 |
  _____mom_____     _____dad_____
 |             |   |             |
mom___     ___dad mom___     ___dad___
 |    |   |    |   |    |   |    |    |
mom  dad mom  dad mom  dad mom  dad  mom


|             |   |             |
mom___     ___dad mom___     ___dad___
 |    |   |    |   |    |   |    |    |
mom  dad mom  dad mom  dad mom  dad  mom



  ___dad___
 |    |    |
mom  dad  mom



mom  dad  mom

Name: Anonymous 2007-11-27 13:11

>>33
Oh lawd tree zoom.

Name: Anonymous 2007-11-27 13:21

>>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.

Also sage.

Name: Anonymous 2007-11-27 15:28

Name: Anonymous 2007-11-27 16:16

a simple binary tree?

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...

i suppose a single tree will do it

Name: Anonymous 2007-11-27 16:37

>>8
gfto off our /prog/, 'tard.

You're a unifag who can't google or figure out binary trees. We're  superior to you in every way.

Read SICP.

Name: Anonymous 2007-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: Anonymous 2007-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.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List