Ejemplo n.º 1
0
        public static void Demo()
        {
            var stack = new StackLinkList <object>();

            //Console.WriteLine(stack.Peek());
            //Console.WriteLine(stack.Pop());
            stack.Push(1);
            stack.Push("Basant");
            stack.Push(3);
            stack.Push(4);
            stack.PrintStackItems();
            Console.WriteLine("printing reverse");
            stack.PrintStackItemsReverse();
            Console.WriteLine("printing reverse completed");
            Console.WriteLine(stack.Peek());
            Console.WriteLine(stack.Pop());
            Console.WriteLine(stack.Pop());
            Console.WriteLine(stack.Pop());
            Console.WriteLine(stack.Pop());
            Console.WriteLine(stack.Pop());
            Console.WriteLine(stack.Pop());
            stack.Push(10);
            stack.Push(21);
            stack.Push(31);
            Console.WriteLine(stack.Pop());
            Console.WriteLine($"Count: {stack.Count()}");
            stack.Clear();
            Console.WriteLine(stack.Pop());
        }
Ejemplo n.º 2
0
        public static void Demo()
        {
            var stack = new StackLinkList <string>();

            while (true)
            {
                Console.Write("\nEnter Space Separated Postfix String (0 or Enter to exit): ");
                var postfixString = Console.ReadLine() ?? "0";
                if (postfixString.Trim() == "0" || postfixString.Trim() == "")
                {
                    return;
                }
                var postfixList = postfixString.Split(' ');

                var validString = true;

                foreach (var token in postfixList)
                {
                    switch (GetTokenType(token))
                    {
                    case "Operand":
                        stack.Push(token);
                        break;

                    case "Operator":
                        var op2 = stack.Pop();
                        var op1 = stack.Pop();
                        stack.Push(Apply(op1, op2, token).ToString());
                        break;

                    case "Invalid Token":
                        Console.WriteLine("Invalid character in postfix string");
                        validString = false;
                        break;
                    }
                }
                if (validString)
                {
                    Console.WriteLine($"Result: {stack.Pop()}");
                }
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.Write("\n\t1.Linked List\n\t2.Stack Array\n\t3.Stack Linked List\n\t4.Postfix\n\t5.Infix to Postfix");
                Console.Write("\n\t6.Hash Table\n\t7.Binary Tree\n\t8.Sorting\n\t9.Threaded Binary Tree\n\t10.Binary Tree");
                Console.Write("\n\t11.Heap\n\t0:Exit\nEnter Choice: ");
                var input = Console.ReadLine();
                switch (input)
                {
                case "1":
                    MyLinkedList <object> .Demo();

                    break;

                case "2":
                    StackArray <int> .Demo();

                    break;

                case "3":
                    StackLinkList <object> .Demo();

                    break;

                case "4":
                    Postfix.Demo();
                    break;

                case "5":
                    Postfix.InfixToPostfix();
                    break;

                case "6":
                    HashTable.Demo();
                    break;

                case "7":
                    BST.Demo();
                    break;

                case "8":
                    Sorting.Demo();
                    break;

                case "9":
                    ThreadedBinaryTree.Demo();
                    break;

                case "10":
                    BinaryTree.Demo();
                    break;

                case "11":
                    Heap.Demo();
                    break;

                case "0":
                    return;
                }
            }
        }