• 递归树 查找路径


    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();
            }
        }
    }
  • 相关阅读:
    环境变量设置set env exportFedora Centos日志我的搜狐
    Hadoop Streaming 编程
    业务开发测试HBase之旅三:通过Java Api与HBase交互
    hadoop+zookeeper+hbase安装_dekar_x的空间_百度空间
    HBase Java客户端编程
    Hadoop应用测试
    HBase vs Cassandra: 我们迁移系统的原因
    关于HBase的一些零碎事
    奔流 | 自由、奔放的技术刊物
    Paxos在大型系统中常见的应用场景
  • 原文地址:https://www.cnblogs.com/kexb/p/10333006.html
Copyright © 2020-2023  润新知