Ejemplo n.º 1
0
    void Start()
    {
        #region 手动化


        #region Selector
//		mbt = new BTree();
//				SelectorNode sel = new SelectorNode();
//				mbt.SetRoot(sel);
//
//				TestContionalNode1 tCon1 = new TestContionalNode1();
//				TestActionNode1 tAct1 = new TestActionNode1();
//				sel.childNodes.AddChildNode(tCon1);
//				sel.childNodes.AddChildNode(tAct1);
        #endregion

        #region Sequence
//		mbt = new BTree();
//		SequenceNode seq = new SequenceNode();
//		mbt.SetRoot(seq);
//			TestContionalNode1 tCon1 = new TestContionalNode1();
//			TestActionNode1 tAct1 = new TestActionNode1();
//			seq.childNodes.AddChildNode(tCon1);
//			seq.childNodes.AddChildNode(tAct1);
        #endregion

        #region  杂点的树
        mbt = new BTree();
        SelectorNode selNode = new SelectorNode();
        mbt.SetRoot(selNode);

        SequenceNode      sqnd = new SequenceNode();
        TestContionalNode tCon = new TestContionalNode();
        TestActionNode    tAct = new TestActionNode();
        sqnd.childNodes.AddChildNode(tCon);
        sqnd.childNodes.AddChildNode(tAct);

        SequenceNode       seld  = new SequenceNode();
        TestContionalNode1 tCon1 = new TestContionalNode1();
        TestActionNode1    tAct1 = new TestActionNode1();
        seld.childNodes.AddChildNode(tCon1);
        seld.childNodes.AddChildNode(tAct1);

        //selNode.childNodes.AddChildNode(sqnd);
        //selNode.childNodes.AddChildNode(seld);
        mbt.AddNode(sqnd);
        mbt.AddNode(seld);
        #endregion


        #endregion


        #region 自动化
        // this.mbt = BTreeMgr.GetInstance().GetTree("test1");
        #endregion
    }
Ejemplo n.º 2
0
        BTree <Node> GetFiles(string filename)
        {
            var tree1 = new BTree <Node>
            {
                Data = new Node("文件", "", true)
            };

            var doc     = XElement.Load(cfg.FromFilePath);
            var Targets = doc.Element("Targets");
            var Target  = Targets.Element("Target");
            var Groups  = Target.Element("Groups");

            var Group = Groups.Elements("Group");

            foreach (var grou in Group)
            {
                var aa    = grou.Element("GroupName");
                var tree2 = new BTree <Node>
                {
                    Data = new Node(aa.Value, tree1.Data.Name, false)
                };
                tree1.AddNode(tree2);

                var Files = grou.Elements("Files");
                foreach (var File in Files)
                {
                    var file = File.Elements("File");
                    foreach (var ff in file)
                    {
                        var FilePath = ff.Element("FilePath");
                        if (FilePath != null)
                        {
                            var tree3 = new BTree <Node>
                            {
                                Data = new Node(FilePath.Value, tree2.Data.Name, false)
                            };
                            tree2.AddNode(tree3);
                        }
                    }
                }
            }
            return(tree1);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            List <Int64> data = new List <Int64>();
            string       input;

            while ((input = Console.ReadLine()) != "0")
            {
                data.Add(Convert.ToInt32(input));
            }
            Stopwatch timer = Stopwatch.StartNew();
            Dictionary <Int64, int> nodes = new Dictionary <Int64, int>();

            foreach (var item in data)
            {
                nodes[item] = 0;
            }
            foreach (var item in data)
            {
                nodes[item] += 1;
            }
            HashSet <Int64> values = new HashSet <Int64>();

            foreach (var item in nodes.Keys)
            {
                values.Add(item);
            }
            BTree <int> tree = new BTree <int>();

            foreach (var item in values)
            {
                tree.AddNode(item, nodes[item]);
            }
            timer.Stop();
            Console.WriteLine($"{timer.ElapsedMilliseconds / 1000} s {timer.ElapsedMilliseconds % 1000} ms");
            return;
        }