Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            QueueInheritance queue = new QueueInheritance();
            string           str1  = "hey";
            string           str2  = "hi";
            string           str3  = "hello";
            string           str4  = "there";

            //use method Enqueue to add items to queue
            queue.Enqueue(str1);
            queue.Display();
            queue.Enqueue(str2);
            queue.Display();
            queue.Enqueue(str3);
            queue.Display();
            queue.Enqueue(str4);
            queue.Display();

            // use method Dequeue to remove items from queue
            string removedObject = null;

            // remove items from queue
            try
            {
                removedObject = queue.Dequeue();
                Console.WriteLine($"{removedObject} dequeued");
                queue.Display();
            }
            catch (EmptyListException emptyListException)
            {
                // if exception occurs, write stack trace
                Console.Error.WriteLine(emptyListException.StackTrace);
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //ENVIRONMENT SETUP++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            //creating queue container
            QueueInheritance queue = new QueueInheritance();

            //create string objects to be added to the queue
            string name1 = "Stephanie";
            string name2 = "Alicica";
            string name3 = "Irene";
            string name4 = "Theresa";

            //TESTING INSERTIONS+++++++++++++++++++++++++++++++++++++++++++++++++++++++
            Console.WriteLine("ENQUEUEING items into the queue!");
            Console.WriteLine("---------------------------------------------------------------");
            Console.WriteLine($"ENQUEUEING {name1} into the queue.");
            queue.Enqueue(name1);
            Console.WriteLine("Using List's Display method to see entire contents of the queue:");
            queue.Display();

            Console.WriteLine($"ENQUEUEING {name2} into the queue.");
            queue.Enqueue(name2);
            Console.WriteLine("Using List's Display method to see entire contents of the queue:");
            queue.Display();

            Console.WriteLine($"ENQUEUEING {name3} into the queue.");
            queue.Enqueue(name3);
            Console.WriteLine("Using List's Display method to see entire contents of the queue:");
            queue.Display();

            Console.WriteLine($"ENQUEUEING {name4} into the queue.");
            queue.Enqueue(name4);
            Console.WriteLine("Using List's Display method to see entire contents of the queue:");
            queue.Display();

            //TESTING DELETIONS++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            Console.WriteLine("DEQUEUEING items from the queue!");
            Console.WriteLine("---------------------------------------------------------------");
            string removedName = null;

            try
            {
                while (true)
                {
                    removedName = queue.Dequeue();
                    Console.WriteLine($"{removedName} was dequeued");
                    queue.Display();
                }
            }
            catch (EmptyListException ex)
            {
                Console.WriteLine("\n" + ex.Message);
            }
        }
Ejemplo n.º 3
0
        static void Main()
        {
            QueueInheritance queue = new QueueInheritance();

            queue.Enqueue("Hua");
            queue.Display();
            queue.Enqueue("Mary");
            queue.Display();
            queue.Enqueue("Edward");
            queue.Display();
            queue.Enqueue("Sophia");
            queue.Display();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            #region integerQueue
            // Create a queue of integers
            var integerQueue = new QueueInheritance <int>();

            // Populate values
            integerQueue.Enqueue(42);
            integerQueue.Enqueue(51);
            integerQueue.Enqueue(15);
            integerQueue.Enqueue(33);
            integerQueue.Enqueue(24);

            // Print a queue
            integerQueue.Display();

            // Get last node value
            Console.WriteLine("Last element in integer queue is " + integerQueue.GetLast());
            Console.WriteLine("--------------------------------------------------");
            #endregion

            #region doubleQueue
            // Create a queue of doubles
            var doubleQueue = new QueueInheritance <double>();

            // Populate values
            doubleQueue.Enqueue(42.2);
            doubleQueue.Enqueue(51.1);
            doubleQueue.Enqueue(15.5);
            doubleQueue.Enqueue(33.3);
            doubleQueue.Enqueue(24.4);

            // Print a queue
            doubleQueue.Display();

            // Get last node value
            Console.WriteLine("Last element of double queue is " + doubleQueue.GetLast());
            Console.WriteLine("--------------------------------------------------");
            #endregion

            #region MinumumValue
            // Get minumum node value
            Console.WriteLine("The minimum value of integer queue is " + integerQueue.Minimum());
            Console.WriteLine("--------------------------------------------------");
            Console.WriteLine("The minimum value of double queue is " + doubleQueue.Minimum());
            Console.WriteLine("--------------------------------------------------");
            #endregion
        } // end Main
    public static void test()
    {
        QueueInheritance queue = new QueueInheritance();

        queue.Enqueue("aaa");
        Console.WriteLine(queue.Display());
        queue.Enqueue("bbb");
        Console.WriteLine(queue.Display());
        queue.Enqueue("ccc");
        Console.WriteLine(queue.Display());
        queue.Dequeue();
        Console.WriteLine(queue.Display());
        queue.Dequeue();
        Console.WriteLine(queue.Display());
        Console.ReadKey();
    }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            QueueInheritance queue = new QueueInheritance();

            for (int i = 0; i < 5; ++i)
            {
                Console.Write("Enter a value: ");
                var userInput = Console.ReadLine();
                queue.Enqueue(userInput);
                queue.Display();
            }

            object removedObject = null;

            try
            {
                while (true)
                {
                    removedObject = queue.Dequeue();
                    Console.WriteLine(removedObject + " dequeued");
                    queue.Display();
                }
            }
            catch (EmptyListException emptyListException)
            {
                Console.Error.WriteLine(emptyListException.StackTrace);
            }

            // hold
            Console.ReadKey();
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            QueueInheritance queue = new QueueInheritance();

            // create objects to store in the queue

            //Double anDouble = 34567;
            string aString = "friends";

            // use method Enqueue to add items to queue
            queue.Enqueue("hello");
            queue.Display();
            queue.Enqueue(aString);
            queue.Display();
            queue.Enqueue("how");
            queue.Display();
            queue.Enqueue("are you");
            queue.Display();
        }
Ejemplo n.º 8
0
    static void Main()
    {
        QueueInheritance queue = new QueueInheritance();

        // create objects to store in the queue

        string aString = "hello";
        string bString = "my";
        string cString = "name iS";
        string dString = "MainuL";


        // use method Enqueue to add items to queue
        queue.Enqueue(aString);
        queue.Display();
        queue.Enqueue(bString);
        queue.Display();
        queue.Enqueue(cString);
        queue.Display();
        queue.Enqueue(dString);
        queue.Display();

        // use method Dequeue to remove items from queue
        object removedObject = null;

        // remove items from queue
        try
        {
            while (true)
            {
                removedObject = queue.Dequeue();
                Console.WriteLine($"{removedObject} dequeued");
                queue.Display();
            }
        }
        catch (EmptyListException emptyListException)
        {
            // if exception occurs, write stack trace
            Console.Error.WriteLine(emptyListException.StackTrace);
        }
    }
Ejemplo n.º 9
0
    public static void Main( string[] args )
    {
        QueueInheritance queue = new QueueInheritance();

          // create objects to store in the queue
          bool aBoolean = true;
          char aCharacter = '$';
          int anInteger = 34567;
          string aString = "hello";

          // use method Enqueue to add items to queue
          queue.Enqueue( aBoolean );
          queue.Display();
          queue.Enqueue( aCharacter );
          queue.Display();
          queue.Enqueue( anInteger );
          queue.Display();
          queue.Enqueue( aString );
          queue.Display();

          // use method Dequeue to remove items from queue
          object removedObject = null;

          // remove items from queue
          try
          {
         while ( true )
         {
            removedObject = queue.Dequeue();
            Console.WriteLine( removedObject + " dequeued" );
            queue.Display();
         } // end while
          } // end try
          catch ( EmptyListException emptyListException )
          {
         // if exception occurs, write stack trace
         Console.Error.WriteLine( emptyListException.StackTrace );
          } // end catch
    }
Ejemplo n.º 10
0
        private static void QueTest_Integer()/*The method that instantiates an integer queue,
                                              * displays items, the last node value, and the minimum value in the queue.*/
        {
            QueueInheritance <int> intQueue = new QueueInheritance <int>();

            for (int i = 0; i < intArray().Length; i++)
            {
                intQueue.Enqueue(intArray()[i]);
            }
            intQueue.Display();
            Console.WriteLine($"The last value of this que is {intQueue.GetLastNode()}");
            Console.WriteLine($"The minimum value of this que is {intQueue.Minimum()}");
        }
Ejemplo n.º 11
0
        private static void QueTest_Double()/*The method that instantiates an double queue,
                                             * displays items, the last node value, and the minimum value in the queue.*/
        {
            QueueInheritance <double> doubleQueue = new QueueInheritance <double>();

            for (int i = 0; i < doubleArray().Length; i++)
            {
                doubleQueue.Enqueue(doubleArray()[i]);
            }
            doubleQueue.Display();
            Console.WriteLine($"The last value of this que is {doubleQueue.GetLastNode()}");
            Console.WriteLine($"The minimum value of this que is {doubleQueue.Minimum()}");
        }
Ejemplo n.º 12
0
    public static void Main(string[] args)
    {
        QueueInheritance queue = new QueueInheritance();

        // create objects to store in the queue
        bool   aBoolean   = true;
        char   aCharacter = '$';
        int    anInteger  = 34567;
        string aString    = "hello";

        // use method Enqueue to add items to queue
        queue.Enqueue(aBoolean);
        queue.Display();
        queue.Enqueue(aCharacter);
        queue.Display();
        queue.Enqueue(anInteger);
        queue.Display();
        queue.Enqueue(aString);
        queue.Display();

        // use method Dequeue to remove items from queue
        object removedObject = null;

        // remove items from queue
        try
        {
            while (true)
            {
                removedObject = queue.Dequeue();
                Console.WriteLine(removedObject + " dequeued");
                queue.Display();
            } // end while
        }     // end try
        catch (EmptyListException emptyListException)
        {
            // if exception occurs, write stack trace
            Console.Error.WriteLine(emptyListException.StackTrace);
        } // end catch
    }     // end Main
Ejemplo n.º 13
0
        private static void Main()
        {
            var queue = new QueueInheritance <object>();

            // create objects to store in the queue
            const char   aCharacter = '$';
            const int    anInteger  = 34567;
            const string aString    = "hello";

            // use method Enqueue to add items to queue
            queue.Enqueue(true);
            Console.WriteLine(queue);

            queue.Enqueue(aCharacter);
            Console.WriteLine(queue);

            queue.Enqueue(anInteger);
            Console.WriteLine(queue);

            queue.Enqueue(aString);
            Console.WriteLine(queue);

            // remove items from queue
            try
            {
                while (true)
                {
                    var removedObject = queue.Dequeue();
                    Console.WriteLine($"{removedObject} dequeued");
                    Console.WriteLine(queue);
                }
            }
            catch (EmptyListException emptyListException)
            {
                // if exception occurs, write stack trace
                Console.Error.WriteLine(emptyListException.StackTrace);
            }
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            QueueInheritance queue = new QueueInheritance();

            // create objects to store in the queue

            //Double anDouble = 34567;
            string aString = "how";

            // use method Enqueue to add items to queue
            Console.WriteLine("-----Empty Queue-----");
            queue.Display();
            Console.WriteLine();
            Console.WriteLine("-----First Item Queued-----");
            queue.Enqueue("Hey,");
            queue.Display();
            Console.WriteLine("-----Second Item Queued-----");
            queue.Enqueue(aString);
            queue.Display();
            Console.WriteLine("-----Third Item Queued-----");
            queue.Enqueue("you doin'!!");
            queue.Display();
        }
        static void Main()
        {
            QueueInheritance queue    = new QueueInheritance();
            QueueInheritance queueDbl = new QueueInheritance();

            int[]    intArray = GenerateIntArray(5);
            double[] dblArray = GenerateDblArray(5, 100, 2);

            // Insert generated values into list
            foreach (int e in intArray)
            {
                queue.Enqueue(e);
                queue.Display();
                Console.WriteLine("The last element is " + queue.GetLast() + "\n");
            }

            foreach (double e in dblArray)
            {
                queueDbl.Enqueue(e);
                queueDbl.Display();
                Console.WriteLine("The last element is " + queueDbl.GetLast() + "\n");
            }



            // use method Dequeue to remove items from queue
            object removedObject = null;

            /*
             * // remove items from queue
             * try
             * {
             *  while (true)
             *  {
             *      removedObject = queue.Dequeue();
             *      Console.WriteLine($"{removedObject} dequeued");
             *      queue.Display();
             *  }
             * }
             * catch (EmptyListException emptyListException)
             * {
             *  // if exception occurs, write stack trace
             *  Console.Error.WriteLine(emptyListException.StackTrace);
             * }
             */
        }
        static void Main(string[] args)
        {
            QueueInheritance queue = new QueueInheritance();

            //create data to store in List
            string[] names = { "James", "Alice", "Bill" };

            for (int i = 0; i < names.Length; i++)
            {
                queue.Enqueue(names[i]);
            }

            Console.WriteLine("Get the stack using Enqueue() method----");
            queue.DisplayString();
            Console.WriteLine();

            Console.WriteLine("Remove from front using Dequeue() method----");
            queue.Dequeue();
            queue.DisplayString();
            Console.WriteLine();
        }
Ejemplo n.º 17
0
    static void Main()
    {
        QueueInheritance queue = new QueueInheritance();

        // create objects to store in the queue

        string name_1 = "Antonio";
        string name_2 = "Miriam";
        string name_3 = "Alberto";
        string name_4 = "Fabio";
        string name_5 = "Aline";
        string name_6 = "Sasha";
        string name_7 = "Whisky";

        queue.Enqueue(name_1);
        queue.Enqueue(name_2);
        queue.Enqueue(name_3);
        queue.Enqueue(name_4);
        queue.Enqueue(name_5);
        queue.Enqueue(name_6);
        queue.Enqueue(name_7);
        queue.Display();

        while (true)
        {
            Console.WriteLine("\nQueue - Test");
            Console.WriteLine("1. Enqueue");
            Console.WriteLine("2. Dequeue");
            Console.WriteLine("3. Exit");

            int option = int.Parse(Console.ReadLine());

            switch (option)
            {
            case 1:

                Console.Write("\nEnter new element : ");
                try
                {
                    string elementEnqueue = Console.ReadLine();
                    queue.Enqueue(elementEnqueue);
                    queue.Display();
                }
                catch (EmptyListException emptyListException)
                {
                    Console.Error.WriteLine(emptyListException.StackTrace);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("{0} Exception caught.", ex);
                }
                break;

            case 2:
                Console.Write("\nDequeue : ");
                try
                {
                    //remove one item from queue
                    object removedObject = null;
                    removedObject = queue.Dequeue();
                    Console.WriteLine($"{removedObject} dequeued\n");
                    queue.Display();
                }
                catch (EmptyListException emptyListException)
                {
                    // if exception occurs, write stack trace
                    Console.Error.WriteLine(emptyListException.StackTrace);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("{0} Exception caught.", ex);
                }
                break;

            case 3:

                Environment.Exit(0);
                break;

            default:
                throw new ArgumentException("Value not supported :" + option);
            }
        }
    }
Ejemplo n.º 18
0
        static void Main(string[] args)
        {
            QueueInheritance queue = new QueueInheritance();

            Console.WriteLine("Creating an empty Queue");
            queue.Display();
            Console.WriteLine("Enqueuing the name of the the second and last ruler of the Empire of Brazil:");
            queue.Enqueue("Pedro");
            queue.Enqueue("de Alcântara");
            queue.Enqueue("João");
            queue.Enqueue("Carlos");
            queue.Enqueue("Leopoldo");
            queue.Enqueue("Salvador");
            queue.Enqueue("Bibiano");
            queue.Enqueue("Francisco");
            Console.WriteLine("Half of his name");
            queue.Display();
            queue.Enqueue("Pedro");
            queue.Enqueue("Xavier");
            queue.Enqueue("de Paula");
            queue.Enqueue("Leocádio");
            queue.Enqueue("Miguel");
            queue.Enqueue("Gabriel");
            queue.Enqueue("Rafael");
            queue.Enqueue("Gonzaga");
            Console.WriteLine("Full name of D. Pedro II");
            Console.WriteLine("Dequeuing his name...");
            queue.Display();

            queue.Dequeue();
            queue.Dequeue();
            queue.Dequeue();
            queue.Dequeue();
            queue.Dequeue();
            queue.Dequeue();
            queue.Dequeue();
            queue.Dequeue();
            Console.WriteLine("Half of his name... again!");
            queue.Display();
        }