Пример #1
0
        static void Main(string[] args)
        {
            var linkedList = new MyLinkedList <int>();

            linkedList.Add(5);
            linkedList.Add(7);
            linkedList.Add(8);
            linkedList.Add(7);
            linkedList.Print();
            //linkedList.Delete(10);
            // linkedList.Delete(8);
            //linkedList.Insert(6,3);
            //  linkedList.Reverse();
            //  linkedList.Update(3,1);
            linkedList.Access(1);
            linkedList.Print();
            Console.ReadLine();
        }
Пример #2
0
        public void PrintStackItemsReverse()
        {
            if (_stack.Head == null)
            {
                Console.WriteLine("Stack Empty");
                return;
            }

            //for (int i = 0; i < _size; i++)
            //{
            //    Console.Write(_array[i]);
            //    if (i < _size - 1)
            //        Console.Write(",");
            //    else
            //        Console.WriteLine();
            //}

            MyLinkedList <T> .PrintListReverse(_stack.Head);
        }
        /*  Method find() takes a linked list and a key as its argument and returns true if some node in the
         *  list has the key as its data field, false otherwise.
         */
        public bool find(MyLinkedList list, Object key)
        {
            if (isEmpty()) //Checks if list is empty
            {
                Console.WriteLine("List is empty!");
                return(false);
            }
            Node current = list.head;     //Set pointer to first node in the list

            if (current.data.Equals(key)) //Check if data in first node equals the key
            {
                return(true);
            }
            while (current != null && current.data.Equals(key) == false) //Loop through list until data is found
            {
                current = current.next;
            }
            if (current == null) //If data isn't found return false
            {
                return(false);
            }
            return(true); //If data was found, current wont be null and so we return true
        }
Пример #4
0
 public Stack()
 {
     _stack = new MyLinkedList <T>();
 }
Пример #5
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;
                }
            }
        }