示例#1
0
        public void RemoveDups(SinglyLinkedList singly)
        {
            LinkedList.SNode temp = singly.head;
            LinkedList.SNode prev = null;

            Hashtable lht = new Hashtable
            {
                /**
                 *  Since the first element will never be a duplicate
                 *  we can therefore add it into the hashtable
                 *  as an initial element
                 */
                { temp.data, 1 }
            };

            while (temp.next != null)
            {
                Console.WriteLine(temp.next.data);
                prev = temp;
                CheckStatusAndPerformOperation(temp.next, lht, prev);
                temp = temp.next;
            }

            HelperSLL objHelper = new HelperSLL();

            objHelper.PrintList(singly);
            Console.WriteLine();
            Console.WriteLine("Done");
        }
示例#2
0
        static SinglyLinkedList SingleLinkedListCaller()
        {
            HelperSLL        objHelper    = new HelperSLL();
            SinglyLinkedList myLinkedList = new SinglyLinkedList();

            objHelper.InsertFront(myLinkedList, 1);
            // objHelper.InsertAfter(myLinkedList, 0, 1);
            objHelper.InsertAfter(myLinkedList, 1, 2);
            objHelper.InsertAfter(myLinkedList, 2, 3);
            objHelper.InsertAfter(myLinkedList, 3, 4);
            objHelper.InsertAfter(myLinkedList, 4, 5);
            objHelper.InsertAfter(myLinkedList, 5, 6);
            objHelper.InsertLast(myLinkedList, -1);
            // Console.WriteLine();

            objHelper.PrintList(myLinkedList);
            Console.WriteLine();
            Console.WriteLine("==================");
            return(myLinkedList);
            // objHelper.ReverseLinkedList(myLinkedList);
            // Console.WriteLine();
            // objHelper.FindMiddle(myLinkedList);
            // objHelper.GetLastNode(myLinkedList);
        }