Login   Register  
PHP Classes
elePHPant
Icontem

File: AVL_Test.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Raimund Neumann  >  AVLTree  >  AVL_Test.php  >  Download  
File: AVL_Test.php
Role: Unit test script
Content type: text/plain
Description: Test program with sample subclass NumTree
Class: AVLTree
AVL tree class
Author: By
Last change:
Date: 2002-12-25 09:41
Size: 1,413 bytes
 

Contents

Class file image Download
<?php
/// ---- AVL_test.php ---- Raimund Neumann 18.12.02 16:19
require_once('AVLTree.php');

class 
NumTree extends AVLTree  {
    function 
NumTree$val )  {
        
$this->AVLTree();
        
$this->data $val;
        
$this->depth 1;
    }
    
    function 
add$val )  {
        if( 
$val == $this->data )  {
            echo 
"$val already in tree<BR>\n";
            return ;
        }

        if( 
$val $this->data )  {
            if( 
$this->left === NULL )
                
$this->left =& new NumTree($val);
            else  {
                
$this->left->add$val );
                
$this->balance();
            }
        } else  {
            
assert$val $this->data );
            
            if( 
$this->right === NULL )
                
$this->right =& new NumTree($val);
            else  {
                
$this->right->add$val );
                
$this->balance();
            }
        }
        
           
$this->getDepthFromChildren();
    }
}

$n =& new NumTree);
echo 
$n->toString();
$n->add);
echo 
$n->toString();
$n->add10);
echo 
$n->toString();
$n->add);
echo 
$n->toString();
$n->add);
echo 
$n->toString();
$n->add);
echo 
$n->toString();
$n->add);
echo 
$n->toString();
$n->add);
//$noisy=TRUE;
echo $n->toString();
$n->add);
echo 
$n->toString();
$n->add);
echo 
$n->toString();
$n->add11);
echo 
$n->toString();
$n->add12);
echo 
$n->toString();
?>