[Pb] tree structure Traversal

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.