<pre>
<?php
define(l,'l');
define(r,'r');
$root['data'] = 22;
$root = tree_insert(&$root,20);
$root = tree_insert(&$root,24);
$root = tree_insert(&$root,23);
$root = tree_insert(&$root,23.5);
$root = tree_insert(&$root,19);
$root = tree_insert(&$root,21);
$root = tree_insert(&$root,20.5);
$root = tree_insert(&$root,21.5);
$root = tree_insert(&$root,20.25);
$root = tree_insert(&$root,20.75);
$root = tree_insert(&$root,18);
$root = tree_insert(&$root,19.5);
$root = tree_insert(&$root,18.5);
print_r($root);
function tree_insert($root,$data) {
if($root) {
if($root['data'] < $data) {
$root[r] = tree_insert(&$root[r],$data);
} else {
$root[l] = tree_insert(&$root[l],$data);
}
} else {
$root['data'] = $data;
return $root;
}
return $root;
}
?>
</pre>
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2010
(147)
-
▼
December
(27)
- Google's AROUND Operator for Proximity Search
- Joining all lines in a file with comma
- Mysql db count tables
- linux : extracting a line range from a file
- mediawiki useful tables - pass 1
- Find the minimum difference between two arrays
- Longest sequence of d-dimensional boxes fitting in...
- Encoding/decoding a tree
- Location of an element where index is same as the ...
- Locker design interview question
- interview questions
- Interview question
- Some Interview questions
- php echo print difference
- PHP how to get the browser information
- GET POST difference
- BST in PHP
- Web Security issues
- Cross site scripting attack (Google example)
- Some db performance optimizations
- Data Denormalization guidelines
- Interview question
- generating all the possible permutations in action...
- Dijkstra's_algorithm in PHP
- Yahoo Interview Questions
- Binary Search C recursive and iterative
- Flex Interview Questions
-
▼
December
(27)
No comments:
Post a Comment