Example #1
0
        public void CheckeReverseQueue()
        {
            CustomQueue<double> queue = new CustomQueue<double>();
            queue.EnQueue(3.14);
            queue.EnQueue(8.28);
            queue.EnQueue(1.1987);
            queue.EnQueue(5.39);

            queue.Reverse();
            double element = queue.Dequeue();
            Assert.AreEqual(5.39, element);
        }
Example #2
0
        public void CheckeDequeue()
        {
            CustomQueue<double> queue = new CustomQueue<double>();
            queue.EnQueue(3.14);
            queue.EnQueue(8.28);
            queue.EnQueue(1.1987);
            queue.EnQueue(5.39);

            double element = queue.Dequeue();
            int length = queue.Length;
            Assert.AreEqual(3.14, element);
            Assert.AreEqual(3, length);
        }
Example #3
0
 public void CheckEnqueue()
 {
     CustomQueue<int> queue = new CustomQueue<int>();
     queue.EnQueue(2);
     int length = queue.Length;
     int element = queue.Peek();
     Assert.AreEqual(length, 1);
     Assert.AreEqual(2, element);
 }
Example #4
0
        static void Main(string[] args)
        {
            /*string str;
             * int count;
             * TimerManager manager = new TimerManager();
             * Person p = new Person("Jon", manager);
             * Person a = new Person("Joe", manager);
             * Person b = new Person("Jeffrey", manager);
             *
             * System.Console.WriteLine("Enter the count of seconds:");
             * do
             * {
             *  str = System.Console.ReadLine();
             *
             * } while (!Int32.TryParse(str,out count));
             *
             * manager.SimulateTimer(count*1000);
             */
            CustomQueue <int> queue = new CustomQueue <int>();

            queue.EnQueue(1);
            queue.EnQueue(5);
            queue.EnQueue(10);
            WriteQueue(queue);
            queue.DeQueue();
            WriteQueue(queue);


            System.Console.ReadKey();

            foreach (int number in FibonacciNumbers.GetNubers(10))
            {
                System.Console.WriteLine(number);
            }

            System.Console.ReadKey();
            foreach (int number in FibonacciNumbers.GetNubers(5))
            {
                System.Console.WriteLine(number);
            }

            System.Console.ReadKey();
        }
        public void processData(byte[] data, int dataLength)
        {
            if (que == null)
            {
                que = new CustomQueue(50);
            }

            que.EnQueue(data, dataLength);

            //처리를 위한 thread 생성
            //이미 생성되어 있으면 패스
            if (ThreadPhaser == null)
            {
                ThreadPhaser = new Task(() =>
                                        PhaserThread(this)
                                        );
                ThreadPhaser.Start();
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            // create some test data for the stack and the queue
            string[] text = new string[3];
            text[0] = "De eerste string";
            text[1] = "De tweede string";
            text[2] = "De derde string";

            #region CustomStack test

            Console.WriteLine("CustomStack test (LIFO)");
            // create a stack of the type string
            CustomStack <string> stack = new CustomStack <string>();
            // add the strings to the stack
            for (int i = 0; i <= text.GetUpperBound(0); i++)
            {
                stack.Push(text[i]);
            }

            // remove and show the order of removed items
            for (int i = 0; i <= text.GetUpperBound(0); i++)
            {
                Console.WriteLine("- " + stack.Pop());
            }

            #endregion

            Console.WriteLine();

            #region CustomQueue test

            Console.WriteLine("CustomQueue test (FIFO)");
            // create a generic questom queue
            CustomQueue <string> queue = new CustomQueue <string>();
            // add items to the queue
            for (int i = 0; i <= text.GetUpperBound(0); i++)
            {
                queue.EnQueue(text[i]);
            }

            // remove the items and show the position
            for (int i = 0; i <= text.GetUpperBound(0); i++)
            {
                Console.WriteLine("- " + queue.Peek());
                queue.DeQueue();
            }

            #endregion

            Console.WriteLine();

            #region CustomPriorityQueue test

            Console.WriteLine("CustomPriorityQueue");
            // create a CustomPriorityQueue to simulate a waiting room for patients
            // where priority 0 is first
            CustomPriorityQueue waitingRoom = new CustomPriorityQueue();
            pqItem[]            patients    = new pqItem[4];
            patients[0].name     = "Klaas";
            patients[0].priority = 1;
            patients[1].name     = "Gerald";
            patients[1].priority = 3;
            patients[2].name     = "Tessa";
            patients[2].priority = 0;
            patients[3].name     = "Yvonne";
            patients[3].priority = 7;
            // add all patients to the priority queue
            for (int i = 0; i <= patients.GetUpperBound(0); i++)
            {
                waitingRoom.Enqueue(patients[i]);
            }

            // remove patients from waiting list in order of their priority
            for (int i = 0; i <= patients.GetUpperBound(0); i++)
            {
                pqItem patient = (pqItem)waitingRoom.Dequeue();
                Console.WriteLine(patient.priority + ": " + patient.name);
            }

            #endregion

            Console.ReadKey();
        }
Example #7
0
        static void Main()
        {
            try
            {
                // استک و صف همزمان
                Console.WriteLine("queue: ");
                FifoLifoList <string> fl = new FifoLifoList <string>((int)CollectionNames.Queue);
                fl.Add("a");
                fl.Add("b");
                fl.Add("c");

                Console.WriteLine(fl.Remove().GetData());
                Console.WriteLine(fl.Remove().GetData());

                Console.WriteLine("stack: ");

                // استک و صف همزمان
                FifoLifoList <string> fl2 = new FifoLifoList <string>((int)CollectionNames.Stack);
                fl2.Add("a");
                fl2.Add("b");
                fl2.Add("c");

                Console.WriteLine(fl2.Remove().GetData());
                Console.WriteLine(fl2.Remove().GetData());

                // (استک با پایه آرایه برای سرعت بیشتر (چون ولیو تایپ است
                Console.WriteLine("ArrayBasedStack: ");
                ArrayBasedStack <int> arbStack = new ArrayBasedStack <int>();
                arbStack.Push(1);
                arbStack.Push(2);
                arbStack.Push(3);
                Console.WriteLine(arbStack.Pop());
                Console.WriteLine(arbStack.Pop());

                //---------------------------
                Console.WriteLine("CustomQueue: ");
                CustomQueue <string> cq = new CustomQueue <string>();
                cq.EnQueue("a");
                cq.EnQueue("b");
                cq.EnQueue("c");

                Console.WriteLine(cq.DeQueue().GetData());
                Console.WriteLine(cq.DeQueue().GetData());
                cq.Clear();
                //Console.WriteLine(cq.DeQueue().Data);


                Console.WriteLine("CustomStack: ");
                CustomStack <int> numbers = new CustomStack <int>();
                numbers.Push(1);
                numbers.Push(2);
                numbers.Push(3);
                numbers.Push(4);
                numbers.Push(5);
                numbers.PrintAll();

                Console.WriteLine("Count of stack is: {0}", numbers.Count());

                Console.WriteLine("Popping {0}", numbers.PopData());
                Console.WriteLine("Popping {0}", numbers.PopData());
                numbers.Clear();
                //Console.WriteLine("Popping '{0}'", numbers.Pop2());

                //-------------------
                CustomStack <string> stack = new CustomStack <string>();
                stack.Push("first");
                stack.Push("second");
                stack.Push("third");
                Console.WriteLine("\nall data");
                stack.PrintAll();
                Console.WriteLine("\nPeek");
                Console.WriteLine(stack.PeekFromStack().GetData());
                Console.WriteLine("\nPrintAll again");
                stack.PrintAll();
                Console.WriteLine("\nnow try to pop");
                Console.WriteLine(stack.Pop().GetData());
                Console.WriteLine("\nPrintAll again");
                stack.PrintAll();
                Console.WriteLine("\nnow try to popping two items ");
                Console.WriteLine("Popping {0}", stack.Pop().GetData());
                Console.WriteLine("Popping {0}", stack.Pop().GetData());

                Console.WriteLine("\nPrintAll again");
                stack.PrintAll();
                Console.WriteLine("\nPush three item");
                stack.Push("first");
                stack.Push("second");
                stack.Push("third");
                stack.PrintAll();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #8
0
 public void CheckPeek()
 {
     CustomQueue<double> queue = new CustomQueue<double>();
     queue.EnQueue(3.14);
     queue.EnQueue(6.78);
     double element = queue.Peek();
     Assert.AreEqual(3.14, element);
     Assert.AreEqual(2, queue.Length);
 }
Example #9
0
 public void CheckLength()
 {
     CustomQueue<string> queue = new CustomQueue<string>();
     queue.EnQueue("ABC");
     queue.EnQueue("XYZ");
     Assert.AreEqual(2, queue.Length);
 }
Example #10
0
 public void Contains()
 {
     CustomQueue<double> queue = new CustomQueue<double>();
     queue.EnQueue(3.14);
     queue.EnQueue(8.28);
     queue.EnQueue(1.1987);
     queue.EnQueue(5.39);
     Assert.AreEqual(true, queue.Contains(1.1987));
 }
Example #11
0
 public void CheckReverseCopy()
 {
     CustomQueue<string> queue = new CustomQueue<string>();
     queue.EnQueue("ABC");
     queue.EnQueue("XYZ");
     List<string> revQueue = queue.ReverseCopy().ToList();
     Assert.AreEqual("XYZ", revQueue[0]);
 }