当前位置: 首页>>代码示例>>C#>>正文


C# BinaryTree.Equals方法代码示例

本文整理汇总了C#中BinaryTree.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryTree.Equals方法的具体用法?C# BinaryTree.Equals怎么用?C# BinaryTree.Equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinaryTree的用法示例。


在下文中一共展示了BinaryTree.Equals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            BinaryTree<int> tree = new BinaryTree<int>();
            tree.Insert(2);
            tree.Insert(3);
            tree.Insert(5);
            tree.Insert(8);
            tree.Insert(11);
            tree.Insert(200);
            tree.Insert(120);
            tree.Insert(600);
            Console.WriteLine(tree);
            Console.WriteLine(tree.Count);
           
            tree.Remove(2);
            tree.Remove(5);
            tree.Remove(8);
            Console.WriteLine(tree);
            tree.Remove(11);
            tree.Remove(200);
            tree.Remove(120);
            tree.Remove(600);
            tree.Remove(3);
            Console.WriteLine(tree);
            Console.WriteLine(tree.Count);

            tree.Insert(10);
            tree.Insert(20);
            tree.Insert(30);
            tree.Insert(60);
            tree.Insert(1);
            tree.Insert(500);
            tree.Insert(2);
            Console.WriteLine(tree);
            Console.WriteLine(tree.Count);

            var newTree = new BinaryTree<int>();
            newTree.Insert(10);
            newTree.Insert(20);
            newTree.Insert(30);
            newTree.Insert(60);
            newTree.Insert(1);
            newTree.Insert(500);
            newTree.Insert(2);
            Console.WriteLine(newTree);
            Console.WriteLine(newTree.Count);
            Console.WriteLine(tree.Equals(newTree));


            foreach (var value in tree)
            {
                Console.WriteLine(value);
            }

            BinaryTree<int> r = null;
            Console.WriteLine(tree.Equals(r));
            int a = 5; 
            Console.WriteLine(a.Equals(null));

        }
开发者ID:alex687,项目名称:SoftUni-Homeworks,代码行数:60,代码来源:Program.cs

示例2: Main

    static void Main(string[] args)
    {
        BinaryTree<int> firstTree = new BinaryTree<int>();
        firstTree.AddNode(13);
        firstTree.AddNode(5);
        firstTree.AddNode(12);
        firstTree.AddNode(14);
        firstTree.AddNode(18);
        firstTree.AddNode(15);
        firstTree.AddNode(19);
        firstTree.AddNode(20);
        firstTree.AddNode(13);
        firstTree.AddNode(22);
        firstTree.AddNode(14);
        firstTree.AddNode(18);
        firstTree.AddNode(15);
        firstTree.AddNode(19);
        firstTree.AddNode(20);
        firstTree.AddNode(13);
        firstTree.AddNode(22);

        Console.WriteLine("The first tree - ToString()");
        Console.WriteLine(firstTree.ToString());
        Console.WriteLine();

        BinaryTree<int> secondTree = new BinaryTree<int>();
        secondTree.AddNode(13);
        secondTree.AddNode(5);
        secondTree.AddNode(12);
        secondTree.AddNode(14);
        secondTree.AddNode(18);
        secondTree.AddNode(15);
        secondTree.AddNode(19);
        secondTree.AddNode(20);
        secondTree.AddNode(13);
        secondTree.AddNode(22);

        Console.WriteLine("The second tree - foreach");
        foreach (var node in secondTree)
        {
            Console.Write(node + " ");
        }
        Console.WriteLine();
        Console.WriteLine();
        
        secondTree.DeleteElement(18);
        secondTree.DeleteElement(5);
        secondTree.DeleteElement(12);
        secondTree.DeleteElement(22);
        secondTree.DeleteElement(14);

        Console.WriteLine("The second tree after deleting elements - ToString()");
        Console.WriteLine(secondTree.ToString());
        Console.WriteLine();
        
        //Cloning demonstation
        BinaryTree<int> thirdTree = secondTree.Clone();
        Console.WriteLine("The third tree - ToString()");
        Console.WriteLine(thirdTree.ToString());
        Console.WriteLine();

        if (firstTree != thirdTree)
        {
            Console.WriteLine("The trees are NOT equal!");
        }
        Console.WriteLine();

        if (secondTree.Equals(thirdTree))
        {
            Console.WriteLine("The trees are equal!");
        }
        Console.WriteLine();

        //Search method demonstration - returns bool value
        Console.WriteLine("Found? {0}", thirdTree.Search(23));
        Console.WriteLine("Found? {0}", thirdTree.Search(20));
        Console.WriteLine("Found? {0}", firstTree.Search(-2220));
        Console.WriteLine("Found? {0}", secondTree.Search(1387));
        Console.WriteLine("Found? {0}", firstTree.Search(5));
        Console.WriteLine();

        //---------------------------------------------------------
        //Also we can create the tree using directly the constructor

        BinaryTree<string> fourthTree = new BinaryTree<string>("Hi", new BinaryTree<string>("there", new BinaryTree<string>("mate"), new BinaryTree<string>("What's")), new BinaryTree<string>("up"));
        Console.WriteLine("Fourth tree - ToString()");
        Console.WriteLine(fourthTree.ToString());
    }
开发者ID:ScreeM92,项目名称:Software-University,代码行数:88,代码来源:BST.cs


注:本文中的BinaryTree.Equals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。