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.º 2
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.º 3
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.º 4
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.º 5
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();
        }
Ejemplo n.º 6
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);
        }
    }
        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.º 8
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.º 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 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.º 11
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);
            }
        }
    }