1176 Data Structures and Collections Chapter 23 left (Multiple domain web hosting)

1176 Data Structures and Collections Chapter 23 left subtree. If the insert value is greater than the root-node data, the program determines whether the right subtree is empty (line 85). If so, line 86 allocates a new TreeNode, initializes it with the integer being inserted and assigns the new node to reference right- Node. Otherwise, line 90 recursively calls Insertfor the right subtree to insert the value in the right subtree. Methods InorderTraversal, PreorderTraversal and PostorderTraversal call helper methods InorderHelper (lines 158 171), PreorderHelper (lines 133 146) and PostorderHelper (lines 183 196), respectively, to traverse the tree and print the node values. The purpose of the helper methods in class Treeis to allow the programmer to start a traversal without the need to obtain a reference to the rootnode first, then call the recursive method with that reference. Methods InorderTraversal, PreorderTraversaland PostorderTraversalsimply take the privatereference root and pass it to the appropriate helper method to initiate a traversal of the tree. For the following discussion, we use the binary search tree shown in Fig. 23.19. Method InorderHelper(lines 158 171) defines the steps for an inorder traversal. Those steps are as follows: 1. If the argument is null, return immediately. 2. Traverse the left subtree with a call to InorderHelper(line 164). 3. Process the value in the node (line 167). 4. Traverse the right subtree with a call to InorderHelper(line 170). The inorder traversal does not process the value in a node until the values in that node s left subtree are processed. The inorder traversal of the tree in Fig. 23.19 is 6 13 17 27 33 42 48 Note that the inorder traversal of a binary search tree prints the node values in ascending order. The process of creating a binary search tree actually sorts the data thus, this process is called the binary tree sort. Method PreorderHelper (lines 133 146) defines the steps for a preorder traversal. Those steps are as follows: 1. If the argument is null, return immediately. 2. Process the value in the node (line 139). 3. Traverse the left subtree with a call to PreorderHelper(line 142). 4. Traverse the right subtree with a call to PreorderHelper(line 145). 27 13 42 6 17 33 48 Fig. 23.19 Fig. 23.19Fig. 23.FF19ig. 23.19ig. 23.19A binary search tree.
Note: If you are looking for cheap webhost to host and run your apache application check Vision jboss web hosting services

Leave a Reply