} $LL = new LinkedList(); $LL->insert("Akeda"); $LL->insert("Dwi"); $LL->insert("Stevey"); $LL->insert("Paul"); // Function to test given keyword. function test_searching($keyword = '') { global $LL; if ($LL->search($keyword) !== NULL) { echo "Node with value '{$keyword}' is found\n"; echo "The previous node of '{$keyword}' is : " . $LL->getPrev() . "\n"; echo "The next node of '{$keyword}' is : " . $LL->getNext() . "\n"; } else { echo "Node with value '{$keyword}' is NOT found\n"; } echo "\n"; } // Test searching of node in linked list test_searching("Akeda"); test_searching("Someone else"); test_searching("Dwi"); test_searching("Paul"); // Delete Stevey $LL->delete("Stevey"); // The next and prev references were updated after delete operation. echo "After 'Stevey' is deleted: \n\n"; test_searching("Dwi"); test_searching("Paul");
$BST = new BinarySearchTree(); $BST->insert(15); $BST->insert(6); $BST->insert(18); $BST->insert(3); $BST->insert(7); $BST->insert(17); $BST->insert(20); $BST->insert(2); $BST->insert(4); $BST->insert(13); $BST->insert(9); function test_searching($num) { global $BST; $node = $BST->search($num); if ($node->val() !== NULL) { echo "Node with value {$num} is found\n"; echo "Parent's node = " . $node->parent() . "\n"; echo "Left-child's node = " . $node->left() . "\n"; echo "Right-child's node = " . $node->right() . "\n"; } else { echo "Node with value {$num} is NOT found\n"; } echo "\n"; } test_searching(7); test_searching(15); test_searching(3); test_searching(2);