static void Main(string[] args)
        {
            List <int> NumberArray = new List <int> {
                79, 69, 9, 95, 65, 49, 65, 40, 27, 95
            };

            //Sorted List elements
            foreach (int n in MergeSort.DivideSortList(NumberArray))
            {
                //Console.Write(n + " ");
            }
            //Console.WriteLine(MergeSort.DivideArray(NumberArray).LastOrDefault());

            /**************
            *
            * START QUEUE
            *
            * ************/
            CustomQueue q = new CustomQueue();

            CustomQueue.IsEmpty();
            CustomQueue.Dequeue();
            CustomQueue.Enqueue(10);
            CustomQueue.Enqueue(20);
            CustomQueue.Enqueue(30);
            CustomQueue.Enqueue(40);
            CustomQueue.Enqueue(50);
            CustomQueue.Enqueue(60);
            CustomQueue.Dequeue();
            CustomQueue.Dequeue();
            CustomQueue.Dequeue();
            CustomQueue.Dequeue();
            CustomQueue.Dequeue();
            CustomQueue.Dequeue();
            CustomQueue.Peek();

            Console.WriteLine(q.ToString());

            /**************
            *
            * END OF QUEUE
            *
            * ************/



            /***
             * Stack implementation
             */
            /*Stack MyStack = new Stack(5);
             * MyStack.Push(20);
             * MyStack.Push(10);
             * MyStack.Push(1);
             * MyStack.Push(6);
             * MyStack.Push(12);
             * MyStack.Push(76);
             * Console.WriteLine(MyStack.ToString());
             * //MyStack.Pop();
             * //MyStack.Pop();
             * //MyStack.Pop();
             * Console.WriteLine(MyStack.ToString());*/
            /**************
            *
            * END OF STACK
            *
            * ************/

            /**************
            *
            * PRIME NUMBERS
            *
            * ************/
            //Console.WriteLine ("PRIME NUMBER OPERATIONS");
            //Console.WriteLine("Is 4567679111 a Prime Number " + PrimeNumbers.IsPrime(456767911));
            //PrimeNumbers.PrintPrimeNumberBtn100and500();

            /******
             * LINKEDLIST
             *
             * ********/
            SingleLinkedList singleLinkedList = new SingleLinkedList("Initial Value");

            singleLinkedList.AddNodeFirst("Samuel1");
            singleLinkedList.AddNodeFirst("Samuel2");
            singleLinkedList.AddNodeFirst("Samuel3");
            singleLinkedList.AddNodeFirst("Samuel4");
            //singleLinkedList.PrintListValues();
            //singleLinkedList.RemoveFirst();
            singleLinkedList.RemoveLast();
            singleLinkedList.PrintListValues();
            Console.WriteLine("============================Before");
            Node matechedNode1 = singleLinkedList.FindNode("Samuel1");

            singleLinkedList.AddBefore(matechedNode1, "MaShalby", true);
            Console.WriteLine("============================After");
            singleLinkedList.AddAfter(matechedNode1, "MaShalby", true);
            //  Console.WriteLine("Matched Node= " + matechedNode1.ToString());
            Console.WriteLine("List size is: " + singleLinkedList.Size());
            Console.WriteLine("End of the first list");

            SingleLinkedList singleLinkedList2 = new SingleLinkedList("Initial last value ");

            Console.WriteLine("AddNodeLast.............: " + singleLinkedList2.Size());
            singleLinkedList2.AddNodeLast("last Samuel 2");
            singleLinkedList2.AddNodeLast("last Samuel3");
            singleLinkedList2.AddNodeLast("last Samuel4");

            //singleLinkedList2.AddNodeLast("last AddNodeLast");
            //singleLinkedList.Remove("Sam");
            Console.WriteLine("AddNodeLast......SIZE.......: " + singleLinkedList2.Size());
            //singleLinkedList2.PrintListValues();
            //singleLinkedList2.Remove("last Samuel4");
            //singleLinkedList2.PrintListValues();
            Node matechedNode = singleLinkedList2.FindNode("last Samuel3");

            Console.WriteLine("Matched Node= " + matechedNode.ToString());
            //Console.WriteLine("Remove Node Above Node:  ");
            singleLinkedList2.PrintListValues();
            singleLinkedList2.AddAfter(matechedNode, "SHALBY", true);
            //singleLinkedList2.PrintListValues();
            //singleLinkedList2.removeNode(matechedNode,true);
            singleLinkedList2.Find("last Samuel3");
            //singleLinkedList2.Find("SHALBY");



            /*******
            * BINARY TREE OPERATIONS
            *
            * *****/
            Console.WriteLine("ADVANCE DATASTRUCTURE");
            Console.WriteLine("BINARY TREE");
            TreeNode BinaryTree = new TreeNode(19);

            BinaryTree.Insert(33);
            BinaryTree.Insert(3);
            BinaryTree.Insert(9);
            BinaryTree.Insert(0);
            BinaryTree.Insert(-1);
            BinaryTree.Insert(20);
            //INORDER
            BinaryTree.PrintInorder();
            // Search
            string IsFound = BinaryTree.Contain(20) == true?"Found":"Not Found";

            Console.WriteLine(IsFound);

            /*********
             *
             * Graph Datastructure
             *
             * ********/
            Console.WriteLine("Graph Opertations");
            Graph g = new Graph(4);

            g.AddEdge(0, 1);
            g.AddEdge(1, 2);
            g.AddEdge(2, 3);
            g.AddEdge(3, 0);
            // Print Graph Values
            g.DisplayGraph();


            Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            SingleLinkedList linkedList = new SingleLinkedList();

            linkedList.InsertFront(linkedList, 2);

            // We add one and the head will have data of 2 in it;
            // the next property will be null as its the end

            linkedList.InsertFront(linkedList, 3);

            // if we add another this becomes the head
            // and next becomes the data node with 2 in it
            // and its next is null

            var node = linkedList.FindNode(linkedList, 3);

            linkedList.InsertAfter(node, 4);


            var myNode = linkedList.FindNode(linkedList, 2);

            linkedList.InsertAfter(myNode, 7);

            linkedList.DeleteNodebyKey(linkedList, 2);


            linkedList.ReverseLinkedList(linkedList);


            BinaryTree binaryTree = new BinaryTree();


            // this gets added to the root because there are no other nodes
            // if data is less than it goes on the left.
            // if its more then it goes on the right..
            // so as we are searching - if the value of the data < this node then go left
            // if value of data > this node then go right
            // and progress down the tree to find a space for the data
            // Each pass cuts data in half and improves performance..
            binaryTree.Add(1);
            binaryTree.Add(2);
            binaryTree.Add(7);
            binaryTree.Add(3);
            binaryTree.Add(10);
            binaryTree.Add(5);
            binaryTree.Add(8);

            // what happens if we already have the value

            binaryTree.Add(1);

            AvlTree tree = new AvlTree();

            tree.Add(5);
            tree.Add(3);
            tree.Add(7);
            tree.Add(2);
            tree.Delete(7);
            tree.DisplayTree();


            // LIFO so
            Stack <FootballTeam> stackOfFootballTeams = new Stack <FootballTeam>();

            stackOfFootballTeams.Push(new FootballTeam()
            {
                Name = "Manchester United", ShirtColor = "Red", Stadium = "Old Trafford"
            });
            stackOfFootballTeams.Push(new FootballTeam()
            {
                Name = "Liverpool", ShirtColor = "Red", Stadium = "Anfield"
            });

            var count = stackOfFootballTeams.Count;

            // so first out will be liverpool
            var item = stackOfFootballTeams.Pop();

            // This is a queue so FIFO

            Queue <FootballTeam> queueOfFootballTeams = new Queue <FootballTeam>();

            queueOfFootballTeams.Enqueue(new FootballTeam()
            {
                Name = "Manchester United", ShirtColor = "Red", Stadium = "Old Trafford"
            });
            queueOfFootballTeams.Enqueue(new FootballTeam()
            {
                Name = "Liverpool", ShirtColor = "Red", Stadium = "Anfield"
            });

            // This will be man united.
            var footballTeam = queueOfFootballTeams.Dequeue();

            Console.ReadLine();
        }
示例#3
0
        static void Main(string[] args)
        {
            var array = new int[] { 101, 6, 23, 3, 98, 8, 13, 5, 97, 103 };

            BubbleSort(array);

            var list = new SingleLinkedList <string>();

            PopulateList(list);

            list.PrintList();

            while (true)
            {
                Console.WriteLine("1. Display List");
                Console.WriteLine("2. Count List");
                Console.WriteLine("3. Search List");
                Console.WriteLine("4. Insert at beginning of list");
                Console.WriteLine("5. Insert at end of list");


                Console.WriteLine("Enter your choice:");
                _choice = Convert.ToInt32(Console.ReadLine());

                switch (_choice)
                {
                case 1:
                    list.PrintList();
                    break;

                case 2:
                    Console.WriteLine($"Elements in list: {list.Count()}");
                    break;

                case 3:
                    Console.WriteLine("Enter the element to be searched:");
                    _input = Console.ReadLine();

                    var found = list.Contains(_input);

                    Console.WriteLine($"Element found: {found}");
                    break;

                case 4:
                    Console.WriteLine("Enter the element to insert at front of list:");

                    _input = Console.ReadLine();

                    list.AddFirst(_input);

                    list.PrintList();
                    break;

                case 5:
                    Console.WriteLine("Enter the element to insert at end of list:");

                    _input = Console.ReadLine();

                    list.AddLast(_input);

                    list.PrintList();
                    break;
                }
            }
        }