예제 #1
0
        public T[] GetPreOrderValues()
        {
            T[] resultArray = new T[nodesCount];

            if (nodesCount > 0)
            {
                aStack <RBNode <T> > stack = new aStack <RBNode <T> >();
                stack.Push(root);

                RBNode <T> current;
                int        index = 0;

                while (stack.IsEmpty())
                {
                    current = stack.Pop();

                    if (current != null)
                    {
                        resultArray[index] = current.Value;
                        stack.Push(current.Left);
                        stack.Push(current.Right);
                    }
                }
            }
            else
            {
                resultArray = new T[0];
            }

            return(resultArray);
        }
예제 #2
0
        public void PushOneElement_PopElement_ElementAreSame()
        {
            aStack <object> stack       = new aStack <object>();
            object          testElement = new object();

            stack.Push(testElement);
            object popedElement = stack.Pop();

            Assert.AreEqual(testElement, popedElement);
        }
예제 #3
0
        public void PushTenElements_Pop11Elements_ThrowsException()
        {
            aStack <object> stack = new aStack <object>();

            for (int i = 0; i < 10; i++)
            {
                stack.Push(new object());
            }
            for (int i = 0; i < 11; i++)
            {
                stack.Pop();
            }
        }
예제 #4
0
        public void Push100Elements_PopSame100Elements()
        {
            object[] testArray = new object[100];
            for (int i = 0; i < 100; i++)
            {
                testArray[i] = new object();
            }

            aStack <object> stack = new aStack <object>();

            for (int i = 0; i < 100; i++)
            {
                stack.Push(testArray[i]);
            }
            bool allAreSame = true;

            for (int i = 0; i < 100; i++)
            {
                allAreSame = allAreSame && (testArray[99 - i] == stack.Pop());
            }

            Assert.IsTrue(allAreSame);
        }
예제 #5
0
        public void Pop_EmptyStack_ThrowsException()
        {
            aStack <object> stack = new aStack <object>();

            stack.Pop();
        }