01-21-201112:27 AM
(This post was last modified: 01-21-201101:08 AM by GamingManiac.)
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?
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?