Remove Ads

Share on Facebook Share on Twitter

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Php and binary tree's
#1
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;
}[/code]

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?
Reply
#2
Not me sorry, never did php.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)