Post Reply 
Social Buttons
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Php and binary tree's
Author Message
GamingManiac Offline
Moderator
*******

Trade Count: (0)
Posts: 23
Joined: Jan 2011
Reputation: 3
Post: #1
Php and binary tree's
Im here to ask if anyone knows how to go about coding a binary search tree in php

I have created this countless times in C++ but I am not comfortable enough in php to attempt it

Here is a c++ version I wrote
Code:
void Bank::add(account* data)                                            //Account Add method
{
    if (accroot == NULL)
    {
        accroot = data;
        return;
    }

    account* acurr = accroot;
    account* aprev;
    numb_accounts ++;
    while (acurr)
    {
        aprev = acurr;
        if (data->numb == acurr->numb)
            acurr = acurr->aright;
        if (data->numb > acurr->numb)
            acurr = acurr->aright;
        else
            acurr = acurr->aleft;
    }
    if (data->numb > aprev->numb)
        aprev->aright = data;
    else
        aprev->aleft = data;
}

this adds the numbers to a binary tree based on their value

Any ideas how to do the equivalent in php?

*EDIT* - Just realised that im making this over complicated

Can anyone help me write a php script that, in order to view a page on my site they have to entered a number (ID number) and then have th php check if it is in a text file?
(This post was last modified: 01-21-2011 01:08 AM by GamingManiac.)
01-21-2011 12:27 AM
Find all posts by this user Quote this message in a reply
Ironside Offline
Site Owner
**********

Trade Count: (0)
Posts: 170
Joined: Nov 2010
Reputation: 7
Post: #2
RE: Php and binary tree's
Not me sorry, never did php.
01-21-2011 11:49 AM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: