Traversal of ctreectrl Variables

Source: Internet
Author: User

A tree is a very important data structure. In programming, we often use trees to organize data. Tree traversal is also a common operation. The following two algorithms are provided. The previous one simply traverses all the nodes, and the next one can return the corresponding nodes based on the input conditions.

/** Function: traverse all nodes of ctreectrl * parameter: Tree-The ctreectrl control variable to be traversed and the root node of the hitem-start variable (if you want to change the entire tree, then: hitem = tree. getrootitem () * return value: void */void travelitem (ctreectrl & tree, htreeitem hitem) {htreeitem hcuritem = tree. getchilditem (hitem); htreeitem hnextitem; while (hcuritem) {outputdebugstring (tree. getitemtext (hcuritem); // output node text hnextitem = hcuritem; travelitem (tree, hnextitem); hcuritem = tree. getnextsiblingitem (hcuritem ); }/** Function: return the specified Tree node * parameter: Tree-The ctreectrl control variable to be traversed and the root node of the item-start variable (if you want to change the entire tree, then: hitem = tree. getrootitem (), strtext-itemtext value of the node (return condition) * return value: Specify the handle of the node (if there is no node that meets the search condition, return NULL) */htreeitem finditem (ctreectrl & tree, htreeitem item, cstring strtext) {htreeitem hfind; If (item = NULL) return NULL; while (item! = NULL) {If (tree. getitemtext (item) = strtext) return item; If (tree. itemhaschildren (item) {item = tree. getchilditem (item); hfind = finditem (tree, item, strtext); If (hfind) {return hfind;} else {item = tree. getnextsiblingitem (tree. getparentitem (item) ;}} else {item = tree. getnextsiblingitem (item); If (item = NULL) return NULL;} return item ;}
Related Article

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.