private static void Main()
        {
            var studentStack = new CustomStack<Student>();
            studentStack.Push(new Student("Pesho", 22));
            studentStack.Push(new Student("Penka", 41));
            studentStack.Push(new Student("Gosho", 7));
            studentStack.Push(new Student("Kuci", 15));

            Console.WriteLine(studentStack.Min().Name);

            var intStack = new CustomStack<int>();

            intStack.Push(4);
            intStack.Push(5);
            intStack.Push(14);
            intStack.Push(42);
            intStack.Push(455);

            intStack.Pop();
            intStack.Pop();

            Console.WriteLine(intStack.Min());

            intStack.Clear();

            Console.WriteLine(intStack.Count);
            Console.WriteLine(intStack.IsEmpty);
            Console.WriteLine(intStack);
        }
Beispiel #2
0
        public static void Main()
        {
            var stack = new CustomStack<int>();
            new List<int> { 1, 2, 3, 4, 5 }.ForEach(x => stack.Push(x));

            while (stack.Count > 0)
            {
                Console.WriteLine(stack.Pop());
            }
        }
        public void Push_ToFixedCapacityStack_ShouldResizeCorrectly()
        {
            var fixedStack = new CustomStack<string>(2);
            int expectedCount = 100;

            for (int i = 0; i < 100; i++)
            {
                fixedStack.Push(i.ToString());
            }

            Assert.AreEqual(expectedCount, fixedStack.Count);
        }
Beispiel #4
0
        public void CustomStack_StackPushTest()
        {
            var actual = new CustomStack<int>();
            for (int i = 0; i < 10; i++)
            {
                actual.Push(i);
            }

            const int expected = 10;

            Assert.AreEqual(actual.Count, expected);
        }
        public void Pop_ItemsInStack_ShouldReturnLastPushedItem_ByReference()
        {
            var items = new CustomStack<StringBuilder>();
            var stringBuilder1 = new StringBuilder("Text");
            var stringBuilder2 = new StringBuilder("Another text");

            items.Push(stringBuilder1);
            items.Push(stringBuilder2);

            var builder = items.Pop();

            Assert.AreSame(stringBuilder2, builder);
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            ICustomStack<int> sample = new CustomStack<int>();

            sample.Push(1);
            sample.Push(2);
            sample.Push(3);

            Console.WriteLine(sample.Pop() + " pop");
            Console.WriteLine(sample.Pop() + " pop");
            Console.WriteLine(sample.Peek() + " peek");
            Console.WriteLine(sample.Pop() + " pop");
        }
        public void CustomStack_StackPushTest()
        {
            CustomStack<int> myStack = new CustomStack<int>();

            for (int i = 0; i < 10; i++)
            {
                myStack.Push(i);
            }

            int expected = 10;

            Assert.AreEqual(expected, myStack.Count);
        }
Beispiel #8
0
        public static void Main()
        {
            CustomStack<int> bsd = new CustomStack<int>();
            bsd.Push(5);
            bsd.Push(3);
            bsd.Push(1);
            Console.WriteLine(bsd.Peek());
            Console.WriteLine(bsd.Pop());

            int[] arr = bsd.ToArray();

            Console.WriteLine(bsd.Pop());
        }
        public static void Main()
        {
            CustomStack<int> numbers = new CustomStack<int>();

            numbers.Push(5);
            numbers.Push(6);
            numbers.Push(2);
            numbers.Push(7);
            numbers.Push(8);

            Console.WriteLine(string.Join(", ",numbers));
            Console.WriteLine(numbers.Pop());
            Console.WriteLine(string.Join(", ", numbers));
        }
        public static void Main()
        {
            var stack = new CustomStack<int>();

            for (int i = 0; i < 15; i++)
            {
                stack.Push(i + 1);
            }

            while (stack.Count > 0)
            {
                Console.WriteLine(stack.Pop());
            }
        }
        public void CustomStack_CorrectElementPeekTest()
        {
            CustomStack<int> myStack = new CustomStack<int>();

            for (int i = 0; i < 10; i++)
            {
                myStack.Push(i);
            }

            int actual = myStack.Peek();
            int expected = 9;

            Assert.AreEqual(expected, actual);
        }
Beispiel #12
0
        public void CustomStack_StackCorrectPeekTest()
        {
            var mystack = new CustomStack<int>();

            for (int i = 0; i < 10; i++)
            {
                mystack.Push(i);
            }

            var actual = mystack.Peek();
            var expected = 9;

            Assert.AreEqual(actual, expected);
        }
        static void Main()
        {
            var testCustomStack = new CustomStack<int>();
            for (int i = 0; i < 10; i++)
            {
                testCustomStack.Push(i + 1);
            }

            Console.WriteLine("Stack size: {0}", testCustomStack.Count);

            while (testCustomStack.Count > 0)
            {
                Console.WriteLine("Stack current top element: {0}", testCustomStack.Pop());
            }
        }
    static void Main(string[] args)
    {
        CustomStack<int> customStack = new CustomStack<int>();

        customStack.Push(123);
        customStack.Push(124);
        customStack.Push(125);
        customStack.Push(1251);

        Console.WriteLine("Stack count: {0}", customStack.Count);

        int number = customStack.Pop();
        Console.WriteLine("Pop an element: {0}", number);
        Console.WriteLine("Peek element: {0}", customStack.Peek());
    }
Beispiel #15
0
        public static void Main(string[] args)
        {
            var stack = new CustomStack<string>();

            stack.Push("pesho");
            stack.Push("gosho");
            stack.Push("vankata");

            Console.WriteLine(stack.Peek());
            Console.WriteLine(stack);

            var popedElement = stack.Pop();
            Console.WriteLine(popedElement);
            Console.WriteLine(stack);
        }
        public static void Main(string[] args)
        {
            CustomStack<int> myStack = new CustomStack<int>();
            List<int> actual = new List<int>();

            for (int i = 0; i < 10; i++)
            {
                myStack.Push(i);
            }

            int[] copy = myStack.ToArray();
            for (int i = 0; i < copy.Length; i++)
            {
                Console.WriteLine(copy[i]);
            }
        }
Beispiel #17
0
 static void Main(string[] args)
 {
     CustomStack<int> stack = new CustomStack<int>();
     stack.Push(3);
     stack.Push(6);
     stack.Push(11);
     stack.Push(91);
     stack.Push(31);
     Console.WriteLine(stack.Peek());
     Console.WriteLine(stack.Peek());
     Console.WriteLine(stack.Peek());
     stack.Push(1001);
     Console.WriteLine(stack.Peek());
     Console.WriteLine(stack.Pop());
     Console.WriteLine(stack.Peek());
 }
Beispiel #18
0
        static void Main(string[] args)
        {
            var myStack = new CustomStack<int>();

            var actual = new List<int>();

            for (int i = 0; i < 10; i++)
            {
                myStack.Push(i);
            }

            foreach (var item in myStack)
            {
                Console.Write(item + " ");
            }

            Console.WriteLine(myStack.Count);
        }
Beispiel #19
0
    /* Task 12: 
     * Implement the ADT stack as auto-resizable array. 
     * Resize the capacity on demand (when no space is available to add / insert a new element).
     */

    static void Main(string[] args)
    {
        var stackArray = new CustomStack<int>();

        for (int i = 1; i <= 100; i++)
        {
            stackArray.Push(i);
        }

        Console.WriteLine("Total Elements Count : {0}", stackArray.Count());
        stackArray.Push(999);
        Console.WriteLine("Total Elements Count : {0}", stackArray.Count());
        Console.WriteLine(stackArray.Pop());
        Console.WriteLine(stackArray.Pop());
        Console.WriteLine(stackArray.Pop());
        Console.WriteLine(stackArray.Pop());
        Console.WriteLine("Total Elements Count : {0}", stackArray.Count());
    }
        public void CustomStack_AccurateStackPopTest()
        {
            CustomStack<int> myStack = new CustomStack<int>();
            List<int> actual = new List<int>();

            for (int i = 0; i < 10; i++)
            {
                myStack.Push(i);
            }

            for (int i = 0; i < 5; i++)
            {
                actual.Add(myStack.Pop());
            }

            List<int> expected = new List<int>() { 9, 8, 7, 6, 5 };

            CollectionAssert.AreEqual(expected, actual);
        }
Beispiel #21
0
    public static void Main()
    {
        CustomStack <int> stack = new CustomStack <int>();

        string line = Console.ReadLine();

        while (line != "END")
        {
            string[] command = line.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();

            if (command[0] == "Push")
            {
                stack.Push(command.Skip(1).Select(x => x.Replace(",", "")).Select(int.Parse).ToArray());
            }
            else if (command[0] == "Pop")
            {
                try
                {
                    stack.Pop();
                }
                catch (Exception e)
                {
                    Console.WriteLine("No elements");
                }
            }

            line = Console.ReadLine();
        }

        foreach (var element in stack)
        {
            Console.WriteLine(element);
        }

        foreach (var element in stack)
        {
            Console.WriteLine(element);
        }
    }
Beispiel #22
0
    static void Main()
    {
        string input;
        var    cStack = new CustomStack <string>();

        try
        {
            while ((input = Console.ReadLine()) != "END")
            {
                var args    = input.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
                var command = args[0];

                switch (command)
                {
                case "Push":
                    var elements = args.Skip(1).ToArray();
                    cStack.Push(elements);
                    break;

                case "Pop":
                    cStack.Pop();
                    break;
                }
            }

            foreach (var item in cStack /*.Reverse()*/)
            {
                Console.WriteLine(item);
            }
            foreach (var item in cStack /*.Reverse()*/)
            {
                Console.WriteLine(item);
            }
        }
        catch (Exception)
        {
            Console.WriteLine("No elements");
        }
    }
        static void Main(string[] args)
        {
            foreach (var result in File.ReadLines(args[0])
                     .Where(line => line != null)
                     .Select(line => line.Split(' ').Select(int.Parse))
                     .Select(
                         values =>
            {
                var stack = new CustomStack();
                foreach (var value in values)
                {
                    stack.Push(value);
                }

                return(stack);
            })
                     .Select(PopAlternate)
                     .Select(values => string.Join(" ", values)))
            {
                Console.WriteLine(result);
            }
        }
    public static void Execute()
    {
        BSTree<int> tree = new BSTree<int>();

        tree.Insert(new BSTNode<int>(5));
        tree.Insert(new BSTNode<int>(10));
        tree.Insert(new BSTNode<int>(8));
        tree.Insert(new BSTNode<int>(20));
        tree.Insert(new BSTNode<int>(2));
        tree.Insert(new BSTNode<int>(100));
        tree.Insert(new BSTNode<int>(1));
        tree.Insert(new BSTNode<int>(3));
        tree.Insert(new BSTNode<int>(80));
        tree.Insert(new BSTNode<int>(7));
        tree.Insert(new BSTNode<int>(19));
        tree.Insert(new BSTNode<int>(9));
        tree.Insert(new BSTNode<int>(110));

        CustomStack<BSTNode<int>> stack = new CustomStack<BSTNode<int>>();

        stack.Push(new linkedNode<BSTNode<int>>(tree.root));

        while (stack.head != null)
        {
            BSTNode<int> cursor = stack.Pop().Data;
            if (cursor == null)
                break;
            Console.WriteLine(cursor.Data);
            BSTNode<int> n = cursor.right;
            if (n != null)
                stack.Push(new linkedNode<BSTNode<int>>(n));
            n = cursor.left;
            if(n!=null)
                stack.Push(new linkedNode<BSTNode<int>>(n));

        }

        stack.Traverse();
    }
Beispiel #25
0
    public static void Main()
    {
        var myStack = new CustomStack<int>();

        string input;
        while ((input = Console.ReadLine()) != "END")
        {
            string[] tokens = input.Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            string command = tokens[0];

            if (command == "Push")
            {
                var numbers = tokens.Skip(1).Select(int.Parse).ToList();

                foreach (var n in numbers)
                {
                    myStack.Push(n);
                }
            }
            else
            {
                try
                {
                    myStack.Pop();
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }
            }
        }

        if (myStack.Any())
        {
            Console.WriteLine(string.Join(Environment.NewLine, myStack));
            Console.WriteLine(string.Join(Environment.NewLine, myStack));
        }
    }
Beispiel #26
0
    static void Main()
    {
        CustomStack <int> customStack = new CustomStack <int>();

        while (true)
        {
            string[] input = Console.ReadLine().Split(" ,".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            if (input[0] == "END")
            {
                break;
            }

            if (input[0] == "Pop")
            {
                try
                {
                    customStack.Pop();
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }
            }
            else if (input[0] == "Push")
            {
                int[] elementsToPush = input.Skip(1).Select(int.Parse).ToArray();

                foreach (int element in elementsToPush)
                {
                    customStack.Push(element);
                }
            }
        }

        Print(customStack);
        Print(customStack);
    }
        static void Main()
        {
            var stack = new CustomStack<int>();

            var studentStack = new CustomStack<Student>();

            studentStack.Push(new Student("Pesho", 12));
            studentStack.Push(new Student("Gosho", 22));
            studentStack.Push(new Student("Minka", 23));
            studentStack.Push(new Student("Stamat", 45));
            studentStack.Push(new Student("Kiril", 33));

            Console.WriteLine(studentStack.Min().Name);

            stack.Push(4);
            stack.Push(3);
            stack.Push(44);
            stack.Push(31);
            stack.Push(12);
            stack.Push(8);

            stack.Pop();
            stack.Pop();

            Console.WriteLine(stack);
            Console.WriteLine(stack.Count);
            Console.WriteLine(stack.IsEmpty);
            Console.WriteLine(stack.Contains(4));
            Console.WriteLine(stack.Contains(111));

            Console.WriteLine(stack.Min());

            stack.Clear();

            Console.WriteLine(stack);
            Console.WriteLine(stack.Count);
            Console.WriteLine(stack.IsEmpty);
        }
Beispiel #28
0
    private static void ParseCommand(string command, CustomStack <int> stack)
    {
        var cmdArgs = command
                      .Split(' ', StringSplitOptions.RemoveEmptyEntries);

        var cmdType = cmdArgs[0];

        switch (cmdType)
        {
        case "Push":
            var elements = cmdArgs
                           .Skip(1)
                           .Select(el => int.Parse(el
                                                   .Split(',', StringSplitOptions.RemoveEmptyEntries)[0]))
                           .ToArray();
            stack.Push(elements);
            break;

        case "Pop":
            stack.Pop();
            break;
        }
    }
 public static void Execute()
 {
     CustomStack<string> stack = new CustomStack<string>();
        stack.Push(new linkedNode<string>("first"));
        stack.Push(new linkedNode<string>("second"));
        stack.Push(new linkedNode<string>("third"));
        stack.Traverse();
        Console.WriteLine("now try to peek");
        Console.WriteLine(stack.Peek().Data);
        Console.WriteLine("traverse again");
        stack.Traverse();
        Console.WriteLine("now try to pop");
        Console.WriteLine(stack.Pop().Data);
        Console.WriteLine("traverse again");
        stack.Traverse();
        Console.WriteLine("pop two more and traverse again");
        stack.Pop(); stack.Pop(); stack.Traverse();
        Console.WriteLine("push the items back and traverse again");
        stack.Push(new linkedNode<string>("first"));
        stack.Push(new linkedNode<string>("second"));
        stack.Push(new linkedNode<string>("third"));
        stack.Traverse();
 }
Beispiel #30
0
    static void Main(string[] args)
    {
        CustomStack <string> theStack = new CustomStack <string>();

        string command;

        while ((command = Console.ReadLine()) != "END")
        {
            string[] commTokens = command.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);

            string currentCommand = commTokens[0];

            if (currentCommand.Equals("Push"))
            {
                theStack.Push(commTokens.Skip(1).ToArray());
            }
            else if (currentCommand.Equals("Pop"))
            {
                try
                {
                    theStack.Pop();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }

        for (int i = 0; i < 2; i++)
        {
            foreach (var element in theStack)
            {
                Console.WriteLine(element);
            }
        }
    }
        public void Test1()
        {
            //["CustomStack","push","push","pop","push","push","push","increment","increment","pop","pop","pop","pop"]
            //    [[3],[1],[2],[],[2],[3],[4],[5,100],[2,100],[],[],[],[]]


            //[null,null,null,2,null,null,null,null,null,103,202,201,-1]
            var stack = new CustomStack(3);

            stack.Push(1);
            stack.Push(2);

            var p_2 = stack.Pop();

            Assert.AreEqual(2, p_2);

            stack.Push(2);
            stack.Push(3);
            stack.Push(4);

            stack.Increment(5, 100);
            stack.Increment(2, 100);

            var p_103 = stack.Pop();

            Assert.AreEqual(103, p_103);
            var p_202 = stack.Pop();

            Assert.AreEqual(202, p_202);
            var p_201 = stack.Pop();

            Assert.AreEqual(201, p_201);
            var p_minus_1 = stack.Pop();

            Assert.AreEqual(-1, p_minus_1);
        }
    public static void Main()
    {
        var    customStack = new CustomStack <int>();
        string command;

        while ((command = Console.ReadLine()) != "END")
        {
            var commandParams = command.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (commandParams[0] == "Push")
            {
                for (int i = 1; i < commandParams.Length; i++)
                {
                    customStack.Push(int.Parse(commandParams[i]));
                }
            }
            else if (commandParams[0] == "Pop")
            {
                if (customStack.Count() == 0)
                {
                    Console.WriteLine("No elements");
                    break;
                }
                else
                {
                    customStack.Pop();
                }
            }
        }

        if (customStack.Count() != 0)
        {
            ForeachTheStack(customStack);
            ForeachTheStack(customStack);
        }
    }
        public static void Main(string[] args)
        {
            var stack = new CustomStack<int>();

            stack.Push(50);
            stack.Push(3);
            stack.Push(56);
            stack.Push(50);
            stack.Push(3);
            stack.Push(56);
            stack.Push(50);
            stack.Push(3);
            stack.Push(56);
            stack.Push(50);
            stack.Push(3);
            stack.Push(56);

            Console.WriteLine(stack.Peek());
            stack.Pop();
            var a = stack.Pop();
            Console.WriteLine(a);

            Console.WriteLine(stack.Contains(56));
        }
Beispiel #34
0
 public Engine(IReader reader, IWriter writer)
 {
     this.reader = reader;
     this.writer = writer;
     stack       = new CustomStack <string>();
 }
        public void PeekShouldThrowWhenStackIsEmpty()
        {
            CustomStack <int> stack = new CustomStack <int>();

            stack.Peek();
        }
        public void EmptyHeadTest()
        {
            var stack = CustomStack <string> .Empty;

            AssertThrows <ArgumentNullException>(() => CustomStack <string> .Head(stack));
        }
        public void EmptyTest()
        {
            var stack = CustomStack <string> .Empty;

            Assert.IsTrue(CustomStack <string> .IsEmpty(stack));
        }
        public void TestPeek_EmptyStack()
        {
            CustomStack <int> stack = new CustomStack <int>();

            Assert.AreEqual(4, stack.Peek());
        }
Beispiel #39
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);
            }
        }
        public void CustomStack_NoRemovePeekTest()
        {
            CustomStack<int> myStack = new CustomStack<int>();

            for (int i = 0; i < 10; i++)
            {
                myStack.Push(i);
            }

            myStack.Peek();
            int expected = 10;

            Assert.AreEqual(expected, myStack.Count);
        }
Beispiel #41
0
        public void CustomStack_StackEmptyPushTest()
        {
            var actual = new CustomStack<int>();

            actual.Pop();
        }
Beispiel #42
0
 public Engine()
 {
     this.isRunning   = true;
     this.customStack = new CustomStack <string>();
 }
Beispiel #43
0
 public void Setup()
 {
     _stack = new CustomStack <int>(StackSize);
 }
Beispiel #44
0
        static void Main(string[] args)
        {
            try
            {
                var binarySearch = new BinarySearch();

                int[] searchExpression = { 1, 2, 3, 4, 6 };

                var resultBinarySearch = binarySearch.Find(searchExpression, 4);

                var funcFibonacci = new FuncFibonacci();

                Console.WriteLine("Fibonacci result: ");


                var result = funcFibonacci.GetSequence(-5);


                foreach (var s in funcFibonacci.GetSequence(15))
                {
                    Console.WriteLine(s);
                }

                var stack = new CustomStack <int>();
                stack.Push(4);
                stack.Push(5);

                var myStackCount = stack.Count;
                var myStackPeek  = stack.Peek();
                stack.Pop();
                stack.Push(34);

                var queue = new CustomQueue <int>();
                queue.Enqueue(2);
                queue.Enqueue(3);
                queue.Enqueue(5);
                queue.Enqueue(12);

                var myQueueCount = queue.Count;
                var peek         = queue.Peek();
                var deQueue      = queue.Dequeue();

                var set1 = new CustomSet <int>();

                set1.Add(1);
                set1.Add(2);
                set1.Add(56);

                var set2 = new CustomSet <int>();

                set2.Add(2);
                set2.Add(4);
                set2.Add(6);

                var difference = set1.Difference(set2);

                var intersection = set1.Intersection(set2);
                var union        = set1.Union(set2);

                Console.WriteLine("\nStack:");
                foreach (var s in stack)
                {
                    Console.WriteLine(s);
                }

                Console.WriteLine("\nQueue: ");
                foreach (var s in queue)
                {
                    Console.WriteLine(s);
                }

                Console.WriteLine("\nSet: ");
                foreach (var s in set1)
                {
                    Console.WriteLine(s);
                }

                Console.ReadLine();
            }
            catch (NullReferenceException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine(e.Message);
            }

            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine();
            }
        }
Beispiel #45
0
 public void CreateStack()
 {
     stack = CustomStack.Instance;
 }
        public void CustomStack_InvalidEmptyStackPopTest()
        {
            CustomStack<int> myStack = new CustomStack<int>();

            myStack.Pop();
        }
 private void Reset()
 {
     newEventObservable = new Subject <IEvent>();
     allEvents          = new CustomStack <IEvent>();
 }
        public void Push_ArgumentNullException_Test()
        {
            CustomStack <string> testStack = new CustomStack <string>();

            Assert.Throws <ArgumentNullException>(() => testStack.Push(null));
        }
Beispiel #49
0
        private static void NewMethod()
        {
            CustomList <Person> people = new CustomList <Person>();

            people.Add(Pupil.GeneratePupil());
            people.Add(Pupil.GeneratePupil());
            people.Add(Pupil.GeneratePupil());
            people.Add(Student.GeneratePupil());
            people.Add(Student.GeneratePupil());
            people.Add(Student.GeneratePupil());

            Console.WriteLine(people.Count);

            foreach (var item in people)
            {
                Console.WriteLine(item.ToString());
            }

            foreach (var item in people)
            {
                Console.WriteLine(item.ToString());
            }

            CustomTree tree = new CustomTree();

            tree.Add(5);
            tree.Add(7);
            tree.Add(3);
            tree.Add(4);
            tree.Add(1);
            tree.Print();
            Console.WriteLine("---------------------------------");
            tree.PrintBfs();
            Console.WriteLine("---------------------------------");
            Console.WriteLine("---------------------------------");
            tree.PrintDfs();
            Console.WriteLine("---------------------------------");

            CustomIdealTree idealTree = new CustomIdealTree();

            idealTree.Add(10);
            idealTree.Add(5);
            idealTree.Add(6);
            idealTree.Add(3);
            idealTree.Add(8);
            idealTree.Print();

            CustomTree transformed = idealTree.TransformToCustomTree();

            transformed.Print();

            CustomStack <int> customStack = new CustomStack <int>(4, false);

            customStack.Push(5);
            Console.WriteLine($"Capacity = {customStack.Capacity}");
            customStack.Push(6);
            Console.WriteLine($"Capacity = {customStack.Capacity}");
            customStack.Push(7);
            Console.WriteLine($"Capacity = {customStack.Capacity}");
            customStack.Push(8);
            Console.WriteLine($"Capacity = {customStack.Capacity}");
            customStack.Push(9);
            Console.WriteLine($"Capacity = {customStack.Capacity}");
            customStack.ReallocateMemmory();
            Console.WriteLine($"Capacity = {customStack.Capacity}");
            customStack.Push(9);
            Console.WriteLine($"Capacity = {customStack.Capacity}");
            customStack.Push(9);
            Console.WriteLine($"Capacity = {customStack.Capacity}");

            while (!customStack.IsEmpty())
            {
                Console.WriteLine(customStack.Pop());
            }

            Custom.Collections.JavaList.CustomList <int> list = new Custom.Collections.JavaList.CustomList <int>();
            list.InsertFirst(10);
            list.InsertFirst(13);
            list.InsertFirst(15);
            list.InsertFirst(3);
            list.InsertFirst(17);
            list.InsertFirst(6);
            Console.WriteLine(list.ToString());
        }
        public static void Show()
        {
            #region MyRegion
            {
                CustomStack <string> stack = new CustomStack <string>();
                foreach (var item in "Eleven-Ivy-NE-Hide".Split("-"))
                {
                    stack.Push(item);
                }

                for (int i = 0; i < 3; i++)
                {
                    Console.WriteLine(stack.Pop());
                    Console.WriteLine(stack.Peek());
                    Console.WriteLine(stack.Pop());
                }
            }
            #endregion


            #region 双向链表
            //1.链表的声明以及节点的定义
            LinkedList <string>     link  = new LinkedList <string>();         //定义链表
            LinkedListNode <string> node1 = new LinkedListNode <string>("E1"); //第一个节点
            LinkedListNode <string> node2 = new LinkedListNode <string>("E2"); //第二个节点s
            LinkedListNode <string> node3 = new LinkedListNode <string>("E3");
            LinkedListNode <string> node4 = new LinkedListNode <string>("E4");

            //2.节点的加入
            link.AddFirst(node1); //加入第一个节点
            link.AddAfter(node1, node2);
            link.AddAfter(node2, node3);
            link.AddAfter(node3, node4);

            //3.计算包含的数量
            Console.WriteLine(link.Count);

            //4.显示
            LinkedListNode <string> current = link.First;
            while (current != null)
            {
                Console.WriteLine(current.Value);
                current = current.Next;
            }

            //5.查找
            LinkedListNode <string> temp = link.Find("jiajia2");
            if (temp != null)
            {
                Console.WriteLine("找到这个节点" + temp.Value);
            }

            //6.定位最后节点
            temp = link.Last;
            Console.WriteLine("最后这个节点" + temp.Value);

            //7.一些删除操作
            link.RemoveFirst();
            link.Remove("jiajia2");
            link.Clear();


            #endregion
        }
        public void TestToString_EmptyStack()
        {
            CustomStack <int> stack = new CustomStack <int>();

            Assert.AreEqual(string.Empty, stack.ToString());
        }
        public void Peek_InvalidOperationException_Test()
        {
            CustomStack <int> testStack = new CustomStack <int>();

            Assert.Throws <InvalidOperationException>(() => testStack.Peek());
        }
Beispiel #53
0
 public CustomStack(CustomStack <T> items) : base(items)
 {
 }
 public void InitializeStack()
 {
     this.stack = new CustomStack<int>();
 }
        public void NotEmptyTest()
        {
            var stack = CustomStack <string> .Cons("Hello", CustomStack <string> .Empty);

            Assert.IsFalse(CustomStack <string> .IsEmpty(stack));
        }
        public void CustomStack_ToArrayTest()
        {
            CustomStack<int> myStack = new CustomStack<int>();

            for (int i = 0; i < 10; i++)
            {
                myStack.Push(i);
            }

            int[] actual = myStack.ToArray();
            int[] expected = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            CollectionAssert.AreEqual(actual, expected);
        }
        public void CustomStack_ContainsFalseTest()
        {
            CustomStack<int> myStack = new CustomStack<int>();

            for (int i = 0; i < 10; i++)
            {
                myStack.Push(i);
            }

            Assert.IsFalse(myStack.Contains(66));
        }
Beispiel #58
0
 public void TearDown()
 {
     stack = null;
 }
Beispiel #59
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();
        }
 public void InitCustomStack()
 {
     this.customStack = new CustomStack <int>();
 }