Ejemplo n.º 1
0
        private void Add_OnClick(object sender, RoutedEventArgs e)
        {
            int number;

            if (input.Text != "" || Int32.TryParse(input.Text, out number))
            {
                //input the new value in the unsorted list
                if (unsortedList.Text == "")
                {
                    s = input.Text;
                }
                else
                {
                    s += " " + input.Text;
                }

                //input the new value in the Tree
                myTree.AddRc(Int32.Parse(input.Text));

                PrintValues();
            }
            else if (input.Text != "")
            {
                MessageBox.Show("Wrong input value given.", "Wrong input detected");
            }
            else
            {
                MessageBox.Show("No value is given.", "No input detected");
            }

            //clear the input field
            input.Clear();
        }
Ejemplo n.º 2
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            Random rnd = new Random();
            int    num;

            lbArray1.Text = "";
            label2.Text   = "";
            num           = rnd.Next(0, 100);
            lbArray1.Text = lbArray1.Text + num.ToString().PadLeft(3);
            MyTree        = new Tree(num);

            int n = Convert.ToInt32(textBox1.Text);

            for (int i = 1; i < n; i++)
            {
                num           = rnd.Next(0, 100);
                lbArray1.Text = lbArray1.Text + num.ToString().PadLeft(3);
                MyTree.AddRc(num);
            }

            string treestring = "";

            MyTree.Print(null, ref treestring);
            label2.Text = treestring;
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Random rnd = new Random();
            int    num;
            string unsortedArray = "";
            string sortedArray   = "";

            num           = rnd.Next(0, 100);
            unsortedArray = unsortedArray + num.ToString().PadLeft(3);
            Tree myTree = new Tree(num);
            int  n      = Convert.ToInt32(Console.ReadLine());

            for (int i = 1; i < n; i++)
            {
                num           = rnd.Next(0, 100);
                unsortedArray = unsortedArray + num.ToString().PadLeft(3);
                myTree.AddRc(num);
            }
            string treeString = "";

            myTree.Print(null, ref treeString);
            Console.WriteLine(treeString);
            Console.ReadKey();
        }
Ejemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            Random rnd = new Random();                                   //Create random number generator
            int    num;                                                  // Hold the random number to be added to the tree

            lblArray1.Text = "";                                         //lblArray1 displays the unsorted list number
            label2.Text    = "";                                         //label2.Text will be sorted list of numbers from the tree
            num            = rnd.Next(0, 100);                           //set the first item int the tree
            lblArray1.Text = lblArray1.Text + num.ToString().PadLeft(3); // add it to the unsorted list string
            MyTree         = new Tree(num);                              //Create the tree with an initail value equal to the first item generated above

            int n = Convert.ToInt32(textBox1.Text);                      //get the number of items to store in the tree

            for (int i = 0; i < n; i++)
            {
                num            = rnd.Next(0, 100);                           //generate a random number to be addeto the tree
                lblArray1.Text = lblArray1.Text + num.ToString().PadLeft(3); //add it to the usorted list string
                MyTree.AddRc(num);                                           //add it to the tree by calling the add recursive method of the tree class (addRc)
            }
            string treestring = "";

            MyTree.Print(null, ref treestring);// Call the print method of the tree classto output the sorted list
            label2.Text = treestring;
        }