예제 #1
0
        public LinkListNode clone()
        {
            LinkListNode next2 = null;

            if (next != null)
            {
                next2 = next.clone();
            }
            LinkListNode head2 = new LinkListNode(data, next2, null);

            return(head2);
        }
예제 #2
0
    {//Write code to remove duplicates from an unsorted link. Follow up: how would you solve this problem if a temp buffer is not allowed?
        static void Main(string[] args)
        {
            LinkListNode first  = new LinkListNode(0, null, null);
            LinkListNode head   = first;
            LinkListNode second = first;

            for (int i = 1; i < 8; i++)
            {
                second = new LinkListNode(i % 2, null, null);
                first.setNext(second);
                second.setPrevious(first);
                first = second;
            }
            LinkListNode cloneA = head.clone();
            LinkListNode cloneB = head.clone();

            Console.WriteLine(cloneA.printForward());
            removeDupe(cloneA);
            Console.WriteLine(cloneA.printForward());

            Console.WriteLine(cloneB.printForward());
            removeDupe2(cloneB);
            Console.WriteLine(cloneB.printForward());
        }