Ejemplo n.º 1
0
 public void setNext(LinkListNode n)
 {
     next = n;
     if (this == last)
     {
         last = n;
     }
     if (n != null && n.prev != this)
     {
         n.setPrevious(this);
     }
 }
Ejemplo n.º 2
0
 public void setNext(LinkListNode n)
 {
     next = n;
     if (this == last)
     {
         last = n;
     }
     if (n != null && n.prev != this)
     {
         n.setPrevious(this);
     }
 }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
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());
        }