zoukankan      html  css  js  c++  java
  • 递归树 查找路径

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace ConsoleApp3
    {
        public class ThreeNode
        {
            public ThreeNode()
            {
                ChildList = new List<ThreeNode>();
                ParentList = new List<ThreeNode>();
                lujing = new List<string>();
            }
            public double value;
            public List<string> lujing;
            public string Sequence;
            public List<ThreeNode> ChildList;
            public List<ThreeNode> ParentList;
            public double[] Probablity;
            public bool IsLeaf;
    
    
    
            public  List<string> gellist()
            {
                List<string> newlist = new List<string>();
                if (this.ChildList.Count > 0)
                {
                    foreach (var item in this.ChildList)
                    {
                        newlist.AddRange(MultList(this.Sequence.ToString(), item.gellist()));
                    }
                }
                else
                {
                    newlist.Add(this.Sequence.ToString());
                }
                this.lujing = newlist;
                return newlist;
            }
    
            public  List<string> MultList(string sequence, List<string> list)
            {
                List<string> newlist = new List<string>();
                if (list.Count > 0)
                {
                    foreach (var item in list)
                    {
                        newlist.Add(sequence + "," + item);
                    }
                }
      
                return newlist;
            }
        }
        class Program
        {
         
            public List<string> AddList(List<string>list1,List<string> list2)
            {
                List<string> newlist = new List<string>();
                newlist.AddRange(list1);
                newlist.AddRange(list2);
                return newlist;
            }
            
          
            static void Main(string[] args)
            {
                ThreeNode root = new ThreeNode() { Sequence = "0" };
                var t11 = new ThreeNode() { Sequence = "11" };
                var t12 = new ThreeNode() { Sequence = "12" };
                var t13 = new ThreeNode() { Sequence = "13" };
                root.ChildList.Add(t11);
                root.ChildList.Add(t12);
                root.ChildList.Add(t13);
    
                var t21 = new ThreeNode() { Sequence = "21" };
                var t22 = new ThreeNode() { Sequence = "22" };
                var t23 = new ThreeNode() { Sequence = "23" };
                var t24 = new ThreeNode() { Sequence = "24" };
                t11.ChildList.Add(t21);
                t11.ChildList.Add(t22);
                t11.ChildList.Add(t23);
    
                t12.ChildList.Add(t22);
                t12.ChildList.Add(t23);
                t12.ChildList.Add(t24);
    
                t13.ChildList.Add(t22);
                t13.ChildList.Add(t23);
                t13.ChildList.Add(t24);
    
                var t31 = new ThreeNode() { Sequence = "31" };
                var t32 = new ThreeNode() { Sequence = "32" };
                var t33 = new ThreeNode() { Sequence = "33" };
                var t34 = new ThreeNode() { Sequence = "34" };
                var t35 = new ThreeNode() { Sequence = "35" };
    
                t21.ChildList.Add(t31);
                t21.ChildList.Add(t32);
                t21.ChildList.Add(t33);
    
                t22.ChildList.Add(t32);
                t22.ChildList.Add(t33);
                t22.ChildList.Add(t34);
    
                t23.ChildList.Add(t33);
                t23.ChildList.Add(t34);
                t23.ChildList.Add(t35);
    
                t24.ChildList.Add(t33);
                t24.ChildList.Add(t34);
                t24.ChildList.Add(t35);
    
                root.gellist();
              
                Console.WriteLine("Hello World!");
    
             
                Console.Read();
            }
        }
    }
  • 相关阅读:
    Excel与Google Sheets中实现线性规划求解
    Optaplanner终于支持多线程并行运行
    【译】Optaplanner开发手册本地化: (0)
    多工序、多机台(产线)环境下的排程要点
    设计Optaplanner下实时规划服务的失败经历
    Optaplanner规划引擎的工作原理及简单示例(2)
    vim 分屏
    vim autocmd
    irun vcs option
    记录
  • 原文地址:https://www.cnblogs.com/kexb/p/10333006.html
Copyright © 2011-2022 走看看