【PB】树型结构的遍历

树型结构遍历

作者:郭宝利  来源:原创  日期:2004.06.27 

树型结构的遍历通常使用递归程序来实现,所以本节给出一个按照内容查找,对树型结构进行遍历,如果和要查找的内容相等,则返回该节点的Handle。函数如下:


/*-----------------------------------------------------------------------------
* 函数名称:long wf_reader(long al_handle,string as_target)
* 函数作用:遍历树型结构,找到指定内容的节点。
* 返 回 值:节点的Handle。
* 算法描述:遍历树型结构,使用递归完成。
* 编写日期:2004.6.26
* 编 写 人:达通兴电脑科技  郭宝利
*----------------------------------------------------------------------------*/
long ll_handle
long ll_handleOld
TreeViewItem ltvi_Item
String ls_label
String ls_data

if tv_1.Getitem(al_handle,ltvi_Item)= -1 then return -1

ls_label=Trim(String(ltvi_Item.label))
ls_data=Trim(String(ltvi_Item.data))

if ls_label = as_target then
	return al_handle
else
	ll_handle = tv_1.FindItem(ChildTreeItem!,al_handle)
end if


if ll_handle > 0 then
	if tv_1.Getitem(ll_handle,ltvi_Item)= -1 then return 0
	ls_label=Trim(String(ltvi_Item.label))
	ls_data=Trim(String(ltvi_Item.data))
	
	if ls_label = as_target then
		return ll_handle//找到了要添加的节点
	else
		return wf_reader(ll_handle,as_target)
	end if
else
	ll_handleOld = al_handle
	ll_handle = tv_1.FindItem(NextTreeItem!,ll_handleOld)
	do while ll_handle < 0
		ll_handle = tv_1.FindItem(ParentTreeItem!,ll_handleOld)
		if ll_handle > 0 then
			ll_handleOld = ll_handle
			ll_handle = tv_1.FindItem(NextTreeItem!,ll_handleOld)
		else
			ll_handle = tv_1.FindItem(NextTreeItem!,ll_handle)
			if ll_handle < 0 then
				return -1
			end if
		end if
	loop
	if tv_1.Getitem(ll_handle,ltvi_Item)= -1 then return -1
	ls_label=String(ltvi_Item.label)
	ls_data=String(ltvi_Item.data)

	if ls_label = as_target then
		return ll_handle//找到了要添加的节点
	else
		return wf_reader(ll_handle,as_target)
	end if
end if


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值