コード例 #1
0
        static void Main(string[] args)
        {
            Tree theTree = new Tree();

            theTree.Insert(43);
            theTree.Insert(10);
            theTree.Insert(42);
            theTree.Insert(14);
            theTree.Insert(52);
            theTree.Insert(32);
            theTree.Insert(10);
            theTree.Insert(21);

            Console.WriteLine("Inorder Traversal : ");
            theTree.Inorder(theTree.ReturnRoot());
            Console.WriteLine(" ");
            Console.WriteLine();
            Console.WriteLine("Preorder Traversal : ");
            theTree.Preorder(theTree.ReturnRoot());
            Console.WriteLine(" ");
            Console.WriteLine();
            Console.WriteLine("Postorder Traversal : ");
            theTree.Postorder(theTree.ReturnRoot());
            Console.WriteLine(" ");
            Console.ReadLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: bindumadhvai/system
        static void Main(string[] args)
        {
            Tree theTree = new Tree();
            int  n = 0, se;

            Console.WriteLine("enter no of elements are there in tree");
            n = Convert.ToInt32(Console.ReadLine());
            if (n > 0)
            //This block is executed when input is more than 0.
            {
                Console.WriteLine("ENTER THE ELEMENTS LEVEL WISE STARTING FROM ROOT TO LEAF NODES");
                for (int i = 0; i < n; i++)
                {
                    theTree.Insert(Convert.ToInt32(Console.ReadLine()));
                }
                Console.WriteLine("Enter the element to be searched");
                se = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("ASCENDING : ");
                theTree.Ascending(theTree.ReturnRoot());
                Console.WriteLine(" ");
                Console.WriteLine();
                Console.WriteLine("DESCENDING :  ");
                theTree.Descending(theTree.ReturnRoot());
                Console.WriteLine(" ");
                Console.WriteLine();
                Node s = theTree.Search(theTree.ReturnRoot(), se);
                if (s != null)
                {
                    Console.WriteLine("ELEMENT FOUND");
                }
                else
                {
                    Console.WriteLine("ELEMENT NOT FOUND");
                }
            }
            else
            {
                Console.WriteLine("NO ELEMENT AVAILABLE TO PERFORM ACTIONS");
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Tree theTree = new Tree();

            theTree.Insert(20);
            theTree.Insert(25);
            theTree.Insert(45);
            theTree.Insert(15);
            theTree.Insert(67);
            theTree.Insert(43);
            theTree.Insert(80);
            theTree.Insert(33);
            theTree.Insert(67);
            theTree.Insert(99);
            theTree.Insert(91);
            Console.WriteLine("Inorder Traversal : ");
            theTree.Inorder(theTree.ReturnRoot());
            Console.WriteLine(" ");
            Console.WriteLine();
            Console.WriteLine("Preorder Traversal : ");
            theTree.Preorder(theTree.ReturnRoot());
            Console.WriteLine(" ");
            Console.WriteLine();
            Console.WriteLine("Postorder Traversal : ");
            theTree.Postorder(theTree.ReturnRoot());
            Console.WriteLine(" ");
            Console.ReadLine();
        }
コード例 #4
0
 static void Main(string[] args)
 {
     Tree theTree = new Tree();
     Random r = new Random(DateTime.Now.Millisecond);
     for (int i = 0; i < 20; i++)
     {
         Trade t = new Trade() { Price = r.Next(1, 100), Time = DateTime.Now };
         theTree.Insert(t);
     }
     //theTree.Insert(20);
     //theTree.Insert(25);
     //theTree.Insert(45);
     //theTree.Insert(15);
     //theTree.Insert(67);
     //theTree.Insert(43);
     //theTree.Insert(80);
     //theTree.Insert(33);
     //theTree.Insert(67);
     //theTree.Insert(99);
     //theTree.Insert(91);
     Console.WriteLine("Inorder Traversal : ");
     theTree.Inorder(theTree.ReturnRoot());
     Console.WriteLine(" ");
     Console.WriteLine();
     Console.WriteLine("Preorder Traversal : ");
     theTree.Preorder(theTree.ReturnRoot());
     Console.WriteLine(" ");
     Console.WriteLine();
     Console.WriteLine("Postorder Traversal : ");
     theTree.Postorder(theTree.ReturnRoot());
     Console.WriteLine(" ");
     Console.WriteLine(" ");
     theTree.print(theTree.ReturnRoot());
     Console.WriteLine(" ");
     Console.ReadLine();
 }