HEEELP [REALLY NEEDED (and i mean REALLY)]

i have to write b-tree database in PHP until sunday and i dunno how to do it…
i mean i know what b-tree database is, but what i dont’ know is - HOW TO SORT IT TO BE BALANCED

it wouldn’t be so urgent, but it’s my condition to pass this semester, or i’ll be saying bye to my college…

here’s the algoritm: http://www.semaphorecorp.com/btp/algo.html

anyone?