コード例 #1
0
        static void Main(string[] args)
        {
            //Create a simple Linked List
            SortedLinkedList list = new SortedLinkedList();

            list.Add(32);
            list.Add(12);
            list.Add(434);
            list.Add(0);
            list.Display();
            System.Console.WriteLine(list.Size());
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello to Linked list!!!!!!!!!!!!!!!");
            LinkedList linkedListLast = new LinkedList();//Created object of LinkedList class

            Console.WriteLine("Insert node");
            linkedListLast.InsertLast(56);
            linkedListLast.InsertLast(30);
            linkedListLast.InsertLast(70);
            linkedListLast.Display();
            //UC-2
            Console.WriteLine("---------------------------------------");
            Console.WriteLine("Insert node at front");
            LinkedList linkedListFront = new LinkedList();

            linkedListFront.InsertFront(70);
            linkedListFront.InsertFront(30);
            linkedListFront.InsertFront(56);
            linkedListFront.Display();
            //UC-3
            Console.WriteLine("---------------------------------------");
            Console.WriteLine("Append new node");
            LinkedList linkedListAppend = new LinkedList();

            linkedListAppend.Append(56);
            linkedListAppend.Append(30);
            linkedListAppend.Append(70);
            linkedListLast.Display();
            //UC-4
            Console.WriteLine("---------------------------------------");
            Console.WriteLine("Add Node In Between End  ");
            LinkedList linkedListForBetween = new LinkedList();

            linkedListForBetween.InsertLast(56);
            linkedListForBetween.InsertLast(70);
            linkedListForBetween.AddNodeAfterNode(30, 56);
            linkedListForBetween.Display();
            //UC5
            Console.WriteLine("---------------------------------------");
            Console.WriteLine("Delete First element ");
            linkedListForBetween.Display();
            linkedListForBetween.DeleteNodeAtFirst();
            linkedListForBetween.Display();
            //UC6
            Console.WriteLine("Delete Last element");
            linkedListLast.Display();
            linkedListLast.DeleteNodeAtLast();
            linkedListLast.Display();
            //UC7
            Console.WriteLine("Search for Node 30");
            LinkedList searchlinkedList = new LinkedList();
            Node       node56           = new Node(56);
            Node       node30           = new Node(30);
            Node       node70           = new Node(70);

            node56.next           = node30;
            node30.next           = node70;
            searchlinkedList.head = node56;
            searchlinkedList.Display();
            searchlinkedList.Display();
            if (searchlinkedList.Search(30))
            {
                Console.WriteLine("Node found");
            }
            else
            {
                Console.WriteLine("Node not found");
            }
            //UC-8
            Console.WriteLine("Add node after node");
            LinkedList linkedListAddAfterNode = new LinkedList();

            linkedListAddAfterNode.InsertLast(56);
            linkedListAddAfterNode.InsertLast(30);
            linkedListAddAfterNode.InsertLast(70);
            linkedListAddAfterNode.AddNodeAfterNode(40, 30);
            linkedListAddAfterNode.Display();

            //UC-9
            Console.WriteLine("Delete node 40");
            linkedListAddAfterNode.Display();
            linkedListAddAfterNode.DeleteNodeWithValue(40);
            linkedListAddAfterNode.Display();
            //UC-10
            Console.WriteLine("Sorted linked list");
            SortedLinkedList sortedLinkedList = new SortedLinkedList();

            sortedLinkedList.AddNode(56);
            sortedLinkedList.AddNode(30);
            sortedLinkedList.AddNode(40);
            sortedLinkedList.AddNode(70);
            sortedLinkedList.Display();

            Console.ReadLine();
        }