遍历多叉树的所有数据


	// 构建一个简单的多叉树
	//          a
	//      /      \
	//     b1       b2
	//    / | \      \
	//   c1 c2 c3     c4
	//      / \       / \
	//     d1  d2    d3  d4
需求:
 删除掉所有conditions中operator=“set”的condition
 //解决方案遍历
 插入到链表中全部进行遍历:a b1 b2 c1 c2 c3 c4 d1 d2 d3 d4
	type Condition struct {
		operator string
		data     string
	}
	type Rule struct {
		Id         int32
		name       string
		conditions []*Condition
		child      []*Rule
	}
	var rule Rule
	consumeList := list.List{}
	consumeList.PushBack(&rule) // 将顶级菜单的id入队列
	for consumeList.Len() > 0 {
		frontData := consumeList.Front()
		curRule, ok := frontData.Value.(*Rule)
		if !ok {
			fmt.Println(status.Error(codes.Unknown, "规则队列解析异常"))
			break
		}
		consumeList.Remove(frontData)
		ConditionNew := make([]*Condition, 0)
		for _, v := range curRule.conditions {
			if v.operator == "set" {
				continue
			}
			ConditionNew = append(ConditionNew, v)
		}
		curRule.conditions = ConditionNew //将去掉“set”的conditons重新赋值给当前的rule的conditions属性
		for _, v := range curRule.child {
			consumeList.PushBack(v)
		}
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值