Tree Structure Traversal
Author: Guo Baoli Source: original date: 2004.06.27
Tree traversal usually uses recursion.ProgramSo this section provides a content-based query to traverse the tree structure. If it is the same as the content to be searched, return the handle of the node. The function is as follows: |
/* Handler * function name: Long wf_reader (long al_handle, string as_target) * function: traverses the tree structure and finds the node of the specified content. * Return value: handle of the node. * Algorithm Description: traverses the tree structure and uses recursion. * Prepared on: 2004.6.26 * Edited by: Da Tong Xing computer technology Guo Baoli * Author */long ll_handlelong operator ltvi_itemstring ls_labelstring ls_dataif TV _1.getitem (al_handle, ltvi_item) =-1 then return-1ls_label = trim (string (ltvi_item.label) ls_data = trim (string (ltvi_item.data) If ls_label = as_target thenreturn identifier = TV _1.finditem (CH Ildtreeitem !, Al_handle) end ifif ll_handle> 0 thenif handle (ll_handle, ltvi_item) =-1 then return 0ls_label = trim (string (ltvi_item.label) ls_data = trim (string (ltvi_item.data )) if ls_label = as_target thenreturn ll_handle // find the node elsereturn wf_reader (ll_handle, as_target) end ifelsell_handleold = handler = TV _1.finditem (nexttreeitem !, Ll_handleold) do while ll_handle <0ll_handle = TV _1.finditem (parenttreeitem !, Ll_handleold) If ll_handle> 0 thenll_handleold = ll_handlell_handle = TV _1.finditem (nexttreeitem !, Ll_handleold) elsell_handle = TV _1.finditem (nexttreeitem !, Ll_handle) If ll_handle <0 thenreturn-1end ifend ifloopif handle (ll_handle, ltvi_item) =-1 then return-1ls_label = string (ltvi_item.label) ls_data = string (ltvi_item.data) if ls_label = as_target thenreturn ll_handle // locate the node elsereturn wf_reader (ll_handle, as_target) end ifend if