Beispiel #1
0
        static void Main(string[] args)
        {
            Queue queue = new Queue();

            queue.EnQueue(5);
            queue.EnQueue(10);
            queue.EnQueue(11);
            queue.Traverse();
            Console.WriteLine("The item at the front of the Queue is: {0}", queue.Peek());
            Console.WriteLine("DeQueueing...");
            queue.DeQueue();
            queue.Traverse();
            Console.WriteLine("EnQueueing...");
            queue.EnQueue(16);
            Console.WriteLine("EnQueueing...");
            queue.EnQueue(25);
            queue.Traverse();
            Console.WriteLine("The item at the front of the Queue is: {0}", queue.Peek());
            Console.WriteLine("DeQueueing...");
            queue.DeQueue();
            Console.WriteLine("DeQueueing...");
            queue.DeQueue();
            queue.Traverse();
            Console.WriteLine("The item at the front of the Queue is: {0}", queue.Peek());
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            try
            {
                Queue <int> q = new Queue <int>();

                Console.WriteLine(q.IsEmpty); // true

                q.EnQueue(1).EnQueue(2).EnQueue(3);

                Console.WriteLine(q.Peek());    // 1
                Console.WriteLine(q.DeQueue()); // 1
                Console.WriteLine(q.DeQueue()); // 2

                q.EnQueue(100);

                Console.WriteLine(q.DeQueue()); // 3
                Console.WriteLine(q.DeQueue()); // 100

                Console.WriteLine(q.DeQueue());
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
            finally
            {
                Console.ReadKey();
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Queue queue = new Queue();

            queue.EnQueue(10);
            queue.EnQueue(20);
            queue.DeQueue();
            queue.DeQueue();
            queue.EnQueue(30);
            queue.EnQueue(40);
            queue.EnQueue(50);

            Console.WriteLine("Dequeued item is " + queue.DeQueue().Data);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Queue <int> lol = new Queue <int>();

            lol.Enqueue(20);
            lol.Enqueue(12, true);
            Console.WriteLine(lol.DeQueue());
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            string result;

            Queue<Currencies> myQueue = new Queue<Currencies>();
            do
            {
                Console.WriteLine("1. EnQueue");
                Console.WriteLine("2. DeQueue");
                Console.WriteLine("3. Peek");
                Console.WriteLine("4. Print");
                Console.WriteLine("5. Exit");

                result = Console.ReadLine();

                if (result == "1")
                {
                    Console.WriteLine("Please enter number you would like to add.");
                    myQueue.EnQueue(new Currencies(int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine())));
                    Console.WriteLine();
                }

                if (result == "2")
                {
                    int Popval = myQueue.DeQueue();
                    Console.WriteLine("The top number in the queue is a " + Popval);
                    Console.WriteLine();
                }

                if (result == "3")
                {
                    Console.WriteLine("The top value of the queue is " + myQueue.Peek());
                    Console.WriteLine();
                }

                if (result == "4")
                {
                    myQueue.Print();
                    Console.WriteLine();
                }
            } while (result != "5");
            Queue<Currencies> currencies = new Queue<Currencies>();
            for (int i = 0; i < 10; i++)
            {
                currencies.EnQueue(new Currencies(rand.Next(0,100), rand.Next(0, 100)
            }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            int   input   = 0;
            Queue myQueue = new Queue();

            while (input != 5)
            {
                Console.WriteLine("1. Push a value to the back of the queue");
                Console.WriteLine("2. Peek at the top value of the queue");
                Console.WriteLine("3. Pop the top value from the queue");
                Console.WriteLine("4. Prints the queue");
                Console.WriteLine("5. Exit the program.");

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

                if (input == 1)
                {
                    int input2;
                    Console.WriteLine(" ");
                    Console.Write("What number would you like to add?: ");
                    input2 = int.Parse(Console.ReadLine());

                    myQueue.EnQueue(input2);
                    Console.WriteLine(" ");
                }

                if (input == 2)
                {
                    Console.WriteLine(" ");
                    Console.WriteLine("SPOOKY!!! " + myQueue.Peek() + " is your peeked number.");
                    Console.WriteLine(" ");
                    //myStack.Peek();
                }

                if (input == 3)
                {
                    myQueue.DeQueue();
                }

                if (input == 4)
                {
                    myQueue.Print();
                }
            }
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            Queue<Currencies> myqueue = new Queue<int>();
            int selection;
            do
            {
                Console.WriteLine("1) EnQueue");
                Console.WriteLine("2) Peek");
                Console.WriteLine("3) DeQueue");
                Console.WriteLine("4) Print");
                Console.WriteLine("5) Search");
                Console.WriteLine("6) Exit");



                Console.WriteLine("What do you want to do?");
                selection = int.Parse(Console.ReadLine());
                if (selection == 1)
                {
                    Console.WriteLine("What number do you want to add to your queue?");
                    int pushadd = int.Parse(Console.ReadLine());
                    myqueue.EnQueue(pushadd);
                    Console.WriteLine("Done");

                }
                if (selection == 2)
                {
                    Console.WriteLine("The top value is a " + myqueue.Peek());
                }
                if (selection == 3)
                {

                    

                    int popval = myqueue.DeQueue();
                    
                    if(popval == -1)
                    {
                        Console.WriteLine("Can't, your queue is empty");
                    }
                    else { Console.WriteLine("The top value of the queue is a " + popval); }
                        
                    




                }
                if (selection == 4)
                {

                    myqueue.Print();
                   

                }
                if (selection == 5)
                {

                    myqueue.share();
                }
                QueueGeneric<Currencies> currencies = new QueueGeneric<Currencies>();


                for(int i = 0; i < 10; i++)
                {
                    currencis.Enqueue(new Currencies(Random.Next(0,100), Random.Next(0,100), Random.Next(0,100))
                }







            } while (selection != 6);






        }
Beispiel #8
0
        static void Main(string[] args)
        {
            int         input   = 0;
            Queue <int> myQueue = new Queue <int>();

            //Original: Queue myQueue= new Queue();
            //Because of <T> in the Queue class, you state the type of variable you'd like here



            while (input != 5)
            {
                Console.WriteLine("1. Push a value to the back of the queue");
                Console.WriteLine("2. Peek at the top value of the queue");
                Console.WriteLine("3. Pop the top value from the queue");
                Console.WriteLine("4. Prints the queue");
                Console.WriteLine("5. Exit the program.");

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

                if (input == 1)
                {
                    int input2;
                    Console.WriteLine(" ");
                    Console.Write("What number would you like to add?: ");
                    input2 = int.Parse(Console.ReadLine());

                    myQueue.EnQueue(input2);
                    Console.WriteLine(" ");
                }

                if (input == 2)
                {
                    Console.WriteLine(" ");
                    Console.WriteLine("SPOOKY!!! " + myQueue.Peek() + " is your peeked number.");
                    Console.WriteLine(" ");
                    //myStack.Peek();
                }

                if (input == 3)
                {
                    myQueue.DeQueue();
                }

                if (input == 4)
                {
                    myQueue.Print();
                }

                //Queue<Currencies> currencies = new Queue<Currencies>();
                //currencies.EnQueue(new Currencies(1, 0, 0));
                //currencies.EnQueue(new Currencies(0, 100, 10));
                //currencies.EnQueue(new Currencies(0, 10, 0));
                //currencies.EnQueue(new Currencies(1, 1, 0));

                //currencies.Print();
                //currencies.Sort();

                //Colsole.WriteLine();

                //currencies.Print();

                //for loop
                //currencies.Enqueue(new Currencies(rand.next(0,100), rand.next(0,100), rand.next(0,100)));
            }
        }