예제 #1
0
파일: myGraph.cs 프로젝트: bproorda/401-DSA
        public IEnumerable <Vertex <T> > BreadthFirst(Vertex <T> start)
        {
            foreach (var vertex in Vertices)
            {
                vertex.Visited = false;
            }

            myQueue <Vertex <T> > graphQ = new myQueue <Vertex <T> >();

            graphQ.enQueue(start);

            while (graphQ.Front != null)
            {
                var current = graphQ.deQueue();
                current.Visited = true;
                foreach (var neighbor in current.Neighbors)
                {
                    if (!neighbor.Neighbor.Visited)
                    {
                        graphQ.enQueue(neighbor.Neighbor);
                    }
                }
                yield return(current);
            }
        }
예제 #2
0
        public void TestEnqueue()
        {
            myQueue S = new myQueue();

            S.Enqueue("1");
            S.Enqueue("2");
            S.Enqueue("3");
            Assert.AreEqual(3, S.Count());
        }
예제 #3
0
        static void Main(string[] args)
        {
            myQueue <Customer> myCustomerQ = new myQueue <Customer>();

            myCustomerQ.myq = new Queue <Customer>(10);
            myCustomerQ.Add(new Customer {
                firstname = "Joe", lastname = "Smith"
            });
            myCustomerQ.Add(new Customer {
                firstname = "Sally", lastname = "James"
            });
            myCustomerQ.Add(new Customer {
                firstname = "Mumbo", lastname = "Alex"
            });
            myCustomerQ.Add(new Customer {
                firstname = "Jumbo", lastname = "Smith"
            });
            myCustomerQ.Add(new Customer {
                firstname = "Jack", lastname = "Smith"
            });
            myCustomerQ.Add(new Customer {
                firstname = "Jill", lastname = "Smith"
            });
            myCustomerQ.Add(new Customer {
                firstname = "Went", lastname = "Smith"
            });
            myCustomerQ.Add(new Customer {
                firstname = "Up", lastname = "Smith"
            });
            myCustomerQ.Add(new Customer {
                firstname = "To", lastname = "Smith"
            });
            myCustomerQ.Add(new Customer {
                firstname = "Hill", lastname = "Smith"
            });
            myCustomerQ.Add(new Customer {
                firstname = "Final", lastname = "Smith"
            });

            Console.WriteLine("We can add only 10 item. When we add 11the automatically ger removed from first place.");
            foreach (var item in myCustomerQ.myq)
            {
                Console.WriteLine($"{item.firstname} {item.lastname}");
            }

            Console.WriteLine("After Removing few items to check---------- ");

            myCustomerQ.Remove();
            myCustomerQ.Remove();
            myCustomerQ.Remove();

            foreach (var item in myCustomerQ.myq)
            {
                Console.WriteLine($"{item.firstname} {item.lastname}");
            }
        }
예제 #4
0
        public void TestDequeue()
        {
            myQueue S = new myQueue();

            S.Enqueue("1");
            S.Enqueue("2");
            S.Enqueue("3");
            Assert.AreEqual("1", S.Dequeue());
            Assert.AreEqual("2", S.Dequeue());
        }
예제 #5
0
        public void Can_Create_Empty_Queue_Test()
        {
            //act
            myQueue <int> testQueue = new myQueue <int>();

            //Assert
            Assert.NotNull(testQueue);
            Assert.Null(testQueue.Front);
            Assert.Null(testQueue.Rear);
        }
예제 #6
0
 public T Dequeue()
 {
     if (!Empty())
     {
         LengthStack--;
         T d = prev.data;
         prev = prev.prev;
         return(d);
     }
     return(default(T));
 }
예제 #7
0
        public void Can_enQueue_Test()
        {
            //arrange
            myQueue <string> testQueue = new myQueue <string>();

            //act
            testQueue.enQueue("It worked!");

            //Assert
            Assert.Equal("It worked!", testQueue.Front.Value);
        }
예제 #8
0
        public void Peek_Empty_Queue_Throws_Exception_Test()
        {
            //arrange
            myQueue <int> testQueue = new myQueue <int>();

            //Assert
            Assert.Throws <QueueEmptyException>(() =>
            {
                //act
                testQueue.peek();
            });
        }
예제 #9
0
        public void Does_Peek_Work_Test()
        {
            //arrange
            myQueue <int> testQueue = new myQueue <int>();

            testQueue.enQueue(13);

            //act
            int actual = testQueue.peek();

            //Assert
            Assert.Equal(13, actual);
        }
예제 #10
0
 public void Enqueue(T param)
 {
     if (Empty())
     {
         prev    = new myQueue <T>(param);
         endLink = prev;
     }
     else
     {
         endLink.prev = new myQueue <T>(param);
         endLink      = endLink.prev;
     }
     LengthStack++;
 }
예제 #11
0
        public void Can_enQueue_Multiple_Test()
        {
            //arrange
            myQueue <string> testQueue = new myQueue <string>();

            //act
            testQueue.enQueue("Front");
            testQueue.enQueue("Middle");
            testQueue.enQueue("Rear");

            //Assert
            Assert.Equal("Front", testQueue.Front.Value);
            Assert.Equal("Rear", testQueue.Rear.Value);
        }
예제 #12
0
        public void Can_deQueue_Test()
        {
            //arrange
            myQueue <string> testQueue = new myQueue <string>();

            testQueue.enQueue("First");
            testQueue.enQueue("Second");
            testQueue.enQueue("Third");

            //act
            string actual = testQueue.deQueue();

            //Assert
            Assert.Equal("First", actual);
            Assert.Equal("Second", testQueue.Front.Value);
        }
예제 #13
0
        /************************************************************************************
         *     Implement your version of the PriorityQueue interface below as "myQueue".     *
         *************************************************************************************/
        //Note:  Inner classes are allowed.
        //Note:  Queues should be able to hold an unlimited number of elements (consistent with available memory).
        //Note:  Concentrate on creating a clean, easy to follow solution, using standard langauge features and OO design.


        // *******  Your class called "myQueue" goes here. *******


        /************************************************************************
         *     Implement your version of the PriorityQueue interface above.      *
         *************************************************************************/


        static void Main(string[] args)
        {
            PriorityQueue pq = null;

            //Implement the interface above so that "myQueue" is valid.
            pq = new myQueue();

            // Sample test data/code
            pq.addTask("first", 1);
            pq.addTask("second", 1);
            pq.addTask("third", 3);
            pq.addTask("fourth", 1);
            Console.WriteLine("GetNext(): " + pq.nextTask());
            Console.WriteLine("GetNext(): " + pq.nextTask());
            pq.addTask("fifth", 1);
            pq.addTask("sixth", 5);
            Console.WriteLine("GetNext(): " + pq.nextTask());
            Console.WriteLine("GetNext(): " + pq.nextTask());
            Console.WriteLine("GetNext(): " + pq.nextTask());
            Console.WriteLine("GetNext(): " + pq.nextTask());
            Console.WriteLine("GetNext(): " + pq.nextTask());
            pq.addTask("seventh", 1);
            pq.addTask("eighth", 2);
            pq.addTask("ninth", 2);
            pq.addTask("tenth", 3);
            Console.WriteLine("GetNext(): " + pq.nextTask());
            Console.WriteLine("GetNext(): " + pq.nextTask());
            Console.WriteLine("GetNext(): " + pq.nextTask());
            Console.WriteLine("GetNext(): " + pq.nextTask());
            Console.ReadLine();

            The output for the above should be;

            GetNext() : third;
            GetNext() : first;
            GetNext() : sixth;
            GetNext() : second;
            GetNext() : fourth
                GetNext() : fifth;

            GetNext() : tenth;
            GetNext() : eight;
            GetNext() : ninth;
            GetNext() : seventh

                //Note:  A different set of test data will be used for testing than is provided above. This needs to be an all purpose solution.
        }
예제 #14
0
        public void Can_deQueue_Queue_To_Empty()
        {
            //arrange
            myQueue <int> testQueue = new myQueue <int>();

            testQueue.enQueue(10);
            testQueue.enQueue(11);
            testQueue.enQueue(12);
            testQueue.enQueue(13);
            testQueue.enQueue(14);

            //act
            testQueue.deQueue();
            testQueue.deQueue();
            testQueue.deQueue();
            testQueue.deQueue();
            testQueue.deQueue();
            bool result = testQueue.isEmpty();

            //Assert
            Assert.True(result);
        }
예제 #15
0
 static void Main(string[] args)
 {
     myQueue queue = new myQueue()
 }
예제 #16
0
 public void TestMethod1()
 {
     myQueue acc = new myQueue(10);
 }