コード例 #1
0
        private MyQueue CloneQueue(MyQueue myQ)
        {
            Node    current = myQ.first;
            MyQueue result  = new MyQueue();

            while (current != null)
            {
                result.Add(current.data);
                current = current.next;
            }
            return(result);
        }
コード例 #2
0
        private int SumOfAllNodeItems(MyQueue q)
        {
            Node current = q.first;
            int  sum     = 0;

            while (current != null)
            {
                sum    += current.data;
                current = current.next;
            }
            return(sum);
        }
コード例 #3
0
        private int[] FromQueueToArray(MyQueue q)
        {
            Node       current = q.first;
            List <int> result  = new List <int>();

            while (current != null)
            {
                result.Add(current.data);
                current = current.next;
            }
            return(result.ToArray());
        }
コード例 #4
0
        int Sum(MyQueue q)
        {
            int  result = 0;
            Node n      = q.first;

            while (n != null)
            {
                result += n.data;
                n       = n.next;
            }
            return(result);
        }
コード例 #5
0
        public int[] FillArray(MyQueue q)
        {
            int[] arr  = new int[q.count];
            Node  node = q.first;

            for (int i = 0; i < q.count; i++)
            {
                arr[i] = node.data;
                node   = node.next;
            }
            return(arr);
        }
コード例 #6
0
        public static void ExecQueue()
        {
            MyQueue myQueue = new MyQueue();

            myQueue.IsEmpty();

            myQueue.PrintQueue();

            myQueue.Add(7);

            myQueue.Add("Tina");

            myQueue.Add("11 bytes");

            myQueue.Add(91);

            myQueue.Remove();

            myQueue.PrintQueue();
        }
コード例 #7
0
        public static void Banking()
        {
            Console.WriteLine("How many no of people initially you added into the queue");
            int x = int.Parse(Console.ReadLine());

            Console.WriteLine("Initial cash  that cashier have");
            int     balanch = int.Parse(Console.ReadLine());
            MyQueue qq      = new MyQueue();

            while (x > 0)
            {
                qq.AddQueue();
                int data = qq.WidORdip(balanch);
                if (data < 0)
                {
                    Console.WriteLine("NO farther transition ! soory for that");
                    Environment.Exit(0);
                }
                qq.isProcessComplete();
                qq.DisplayQueue();
                x--;
            }
        }
コード例 #8
0
        static void Main(string[] args)
        {
            //string str= "you can cage a swallow can't you?";
            ////string str = "you shall not pass";
            //Permutation.reverseSentence(str);

            //SortingAlgorithms S = new SortingAlgorithms();
            //S.run();
            //BinarySearch bin = new BinarySearch();
            //bin.run();
            //Permutation.run();
            ////FindPair.Main.run();
            //string str = "ABCDEF";
            //string sub = str.Substring(0, 2);
            //Console.WriteLine(sub);
            //StringBuilder sb = new StringBuilder();

            //ArrayList arrList = new ArrayList();

            //arrList.Add(1);

            //for(int i=0; i < arrList.Count; i++)
            //{
            //    var n = arrList[i];
            //}

            //sb.Append("my name is");
            //sb.Append("");

            //LinkedLists.Main.run();
            MyQueue <int> myQueue = new MyQueue <int>();

            myQueue.run();

            Console.ReadKey();
            Console.WriteLine("Hello World!");
        }
コード例 #9
0
        static void Main(string[] args)
        {
            //variables:
            bool                     bRepeatFullMenu = true, bRepeatInnerMenu = true;
            int                      iMainMenuInput = 0, iInnerMenuInput = 0;
            Stack <string>           my_stack = new Stack <string>();
            Queue <string>           my_queue = new Queue <string>();
            Dictionary <string, int> my_dictionary = new Dictionary <string, int>();
            string                   search_string = "", add_string = "", delete_string = "";


            while (bRepeatFullMenu) //full outer menu loop
            {
                //main menu input loop
                bRepeatFullMenu = true;
                while (bRepeatFullMenu)
                {
                    //display the main menu
                    Console.WriteLine("\nPlease make a selection: ");
                    printMainMenu();

                    try
                    {
                        iMainMenuInput = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine();
                        bRepeatFullMenu = false;

                        //confirm inner menu input
                        if (iMainMenuInput == 1 || iMainMenuInput == 2 || iMainMenuInput == 3)
                        {
                            bRepeatInnerMenu = true;
                        }
                        else if (iMainMenuInput == 4)
                        {
                            Console.WriteLine("Press Enter to exit...");
                            bRepeatFullMenu  = false;
                            bRepeatInnerMenu = false;
                        }
                        else
                        {
                            bRepeatFullMenu  = true;
                            bRepeatInnerMenu = false;
                            Console.WriteLine("Please enter a valid choice\n\n");
                        }


                        while (bRepeatInnerMenu) //inner menus input loop
                        {
                            Console.WriteLine("\nPlease make a selection: ");

                            switch (iMainMenuInput) //print inner menu
                            {
                            case 1:
                                MyStack.printStackMenu();
                                break;

                            case 2:
                                MyQueue.printQueueMenu();
                                break;

                            case 3:
                                MyDictionary.printDictionaryMenu();
                                break;
                            }

                            try
                            {
                                iInnerMenuInput = Convert.ToInt32(Console.ReadLine());
                                Console.WriteLine();
                                bRepeatInnerMenu = false;

                                //inner loop input handling
                                switch (iInnerMenuInput)
                                {
                                case 1:     // add one item

                                    bRepeatInnerMenu = true;
                                    switch (iMainMenuInput)
                                    {
                                    case 1:         // stack
                                        Console.Write("Enter the string: ");
                                        add_string = Convert.ToString(Console.ReadLine());
                                        my_stack   = MyStack.addOne(my_stack, add_string);
                                        break;

                                    case 2:         // queue
                                        Console.Write("Enter the string: ");
                                        add_string = Convert.ToString(Console.ReadLine());
                                        my_queue   = MyQueue.addOne(my_queue, add_string);
                                        break;

                                    case 3:         // dictionary
                                        Console.Write("Enter the string key: ");
                                        add_string = Convert.ToString(Console.ReadLine());
                                        Console.Write("\nEnter the integer value: ");         // TODO add error handling for the integer conversion
                                        try
                                        {
                                            int add_int = Convert.ToInt32(Console.ReadLine());
                                            my_dictionary = MyDictionary.addOne(my_dictionary, add_string, add_int);
                                        }
                                        catch
                                        {
                                            Console.WriteLine("\nNothing added to the dictionary (make sure the key is not duplicate and the integer is valid.\n");
                                        }
                                        break;
                                    }

                                    break;

                                case 2:     // add huge list of items

                                    bRepeatInnerMenu = true;
                                    switch (iMainMenuInput)
                                    {
                                    case 1:         // stack
                                        my_stack = MyStack.addHugeList(my_stack);
                                        break;

                                    case 2:         // queue
                                        my_queue = MyQueue.addHugeList(my_queue);
                                        break;

                                    case 3:         // dictionary
                                        my_dictionary = MyDictionary.addHugeList(my_dictionary);
                                        break;
                                    }

                                    break;

                                case 3:     // display the list

                                    bRepeatInnerMenu = true;
                                    switch (iMainMenuInput)
                                    {
                                    case 1:         // stack
                                        MyStack.display(my_stack);
                                        break;

                                    case 2:         // queue
                                        MyQueue.display(my_queue);
                                        break;

                                    case 3:         // dictionary
                                        MyDictionary.display(my_dictionary);
                                        break;
                                    }

                                    break;

                                case 4:     // delete from the list

                                    bRepeatInnerMenu = true;
                                    switch (iMainMenuInput)
                                    {
                                    case 1:         // stack
                                        Console.Write("Enter the string to delete: ");
                                        delete_string = Convert.ToString(Console.ReadLine());
                                        my_stack      = MyStack.deleteFrom(my_stack, delete_string);
                                        break;

                                    case 2:         // queue
                                        Console.Write("Enter the string to delete: ");
                                        delete_string = Convert.ToString(Console.ReadLine());
                                        my_queue      = MyQueue.deleteFrom(my_queue, delete_string);
                                        break;

                                    case 3:         // dictionary
                                        Console.Write("Enter the string to delete: ");
                                        delete_string = Convert.ToString(Console.ReadLine());
                                        my_dictionary = MyDictionary.deleteFrom(my_dictionary, delete_string);
                                        break;
                                    }

                                    break;

                                case 5:     // clear the list

                                    bRepeatInnerMenu = true;
                                    switch (iMainMenuInput)
                                    {
                                    case 1:         // stack
                                        my_stack = MyStack.clear(my_stack);
                                        break;

                                    case 2:         // queue
                                        my_queue = MyQueue.clear(my_queue);
                                        break;

                                    case 3:         // dictionary
                                        my_dictionary = MyDictionary.clear(my_dictionary);
                                        break;
                                    }

                                    break;

                                case 6:     // search the list

                                    bRepeatInnerMenu = true;
                                    switch (iMainMenuInput)
                                    {
                                    case 1:         // stack
                                        Console.WriteLine("Enter the value you want to search for:");
                                        search_string = Convert.ToString(Console.ReadLine());
                                        my_stack      = MyStack.search(my_stack, search_string);
                                        break;

                                    case 2:         // queue
                                        Console.WriteLine("Enter the value you want to search for:");
                                        search_string = Convert.ToString(Console.ReadLine());
                                        my_queue      = MyQueue.search(my_queue, search_string);
                                        break;

                                    case 3:         // dictionary
                                        Console.WriteLine("Enter the string (key) you want to search for:");
                                        search_string = Convert.ToString(Console.ReadLine());
                                        my_dictionary = MyDictionary.search(my_dictionary, search_string);
                                        break;
                                    }

                                    break;

                                case 7:     // return to the main menu
                                    bRepeatInnerMenu = false;
                                    bRepeatFullMenu  = true;
                                    break;

                                default:     // entered an integer, but not a valid menu item 1-7
                                    bRepeatInnerMenu = true;
                                    Console.WriteLine("Please enter a valid choice\n\n");
                                    break;
                                }
                            }
                            catch
                            {
                                bRepeatInnerMenu = true;
                                Console.WriteLine("Please enter a valid integer");
                            }
                        } // end of inner menu loop
                    }
                    catch
                    {
                        bRepeatFullMenu = true;
                        Console.WriteLine("Please enter a valid integer");
                    }
                }
            } // end of main menu outer loop

            Console.Read();
        }