Exemple #1
0
        //Takes values until "#", then redirects the data for the tree operations and keep stats
        public void run()
        {
            System.IO.StreamReader file = new System.IO.StreamReader(path);
            string firstChar;
            string[] splitLine = new string[2];
            TwoThreeTree tree = new TwoThreeTree();
            TwoFourTree twoFourTree = new TwoFourTree();

            //Read line by line
            while ((line = file.ReadLine()) != null)
            {
                splitLine = line.Split(' ');
                firstChar = splitLine[0];

                //According to the first char of every line, perform an action
                switch (firstChar)
                {
                    case "#":

                        //if it is the first line just create a new stack
                        if (flag)
                        {
                            currentStack = new TreeStack(int.Parse(splitLine[1]));
                            flag = false;

                        }
                        else
                        {
                            //TODO run tree builder
                            currentStack = new TreeStack(int.Parse(splitLine[1]));

                            foreach (var o in currentStack.operations)
                            {
                                if (o.operation == "I")
                                {
                                    tree.Insert(o.number);
                                    twoFourTree.Insert(o.number);

                                }
                                else if (o.operation == "D")
                                {
                                    tree.delete(o.number);
                                    twoFourTree.delete(o.number);
                                }

                                /*
                                Console.Clear();
                                tree.root.PrintNode(1);*/

                                /*Console.Clear();
                                 twoFourTree.root.PrintNode(1);*/

                            }

                            twoFourTree.root.PrintNode(1);
                            tree.root.PrintNode(1);
                            Console.WriteLine("Line Numbers " + counter);
                        }

                        break;

                    case "I":
                        currentStack.Push(new Operation("I", int.Parse(splitLine[1])));
                        break;

                    case "D":
                        currentStack.Push(new Operation("D", int.Parse(splitLine[1])));
                        break;
                }

                counter++;
            }

            //FOr the last set of numbers
            //TwoFourTree twoFourTree = new TwoFourTree();
            foreach (var o in currentStack.operations)
            {
                if (o.operation == "I")
                {
                    tree.Insert(o.number);
                    twoFourTree.Insert(o.number);

                }
                else if (o.operation == "D")
                {
                    tree.delete(o.number);
                    twoFourTree.delete(o.number);
                }

                /*
                Console.Clear();
                tree.root.PrintNode(1);*/

                /*Console.Clear();
                 twoFourTree.root.PrintNode(1);*/

            }

            twoFourTree.root.PrintNode(1);
            tree.root.PrintNode(1);
            Console.WriteLine("Line Numbers " + counter);

            //tree.root.PrintNode(1);

            file.Close();
            Console.ReadLine();
        }
Exemple #2
0
        public void Run()
        {
            System.IO.StreamReader file = new System.IO.StreamReader(path);
            string firstChar;

            string[]     splitLine = new string[2];
            TwoThreeTree tree      = new TwoThreeTree();

            while ((line = file.ReadLine()) != null)
            {
                splitLine = line.Split(' ');
                firstChar = splitLine[0];

                switch (firstChar)
                {
                case "#":

                    if (flag)
                    {
                        currentStack = new TreeStack(int.Parse(splitLine[1]));
                        flag         = false;
                    }
                    else
                    {
                        currentStack = new TreeStack(int.Parse(splitLine[1]));

                        foreach (var o in currentStack.operations)
                        {
                            if (o.operation == "I")
                            {
                                tree.Insert(o.number);
                            }
                            else if (o.operation == "D")
                            {
                                tree.Delete(o.number);
                            }
                        }

                        tree.root.PrintNode(1);
                        Console.WriteLine("Line Numbers " + counter);
                    }

                    break;

                case "I":
                    currentStack.Push(new Operation("I", int.Parse(splitLine[1])));
                    break;

                case "D":
                    currentStack.Push(new Operation("D", int.Parse(splitLine[1])));
                    break;
                }

                counter++;
            }

            foreach (var o in currentStack.operations)
            {
                if (o.operation == "I")
                {
                    tree.Insert(o.number);
                }
                else if (o.operation == "D")
                {
                    tree.Delete(o.number);
                }
            }

            tree.root.PrintNode(1);
            Console.WriteLine("Line Numbers " + counter);

            file.Close();
            Console.ReadLine();
        }