Пример #1
0
 public void setPrevious(LinkListNode p)
 {
     prev = p;
     if (p != null && p.next != this)
     {
         p.setNext(this);
     }
 }
Пример #2
0
 //method 1: copy next node to n, delete next node, O(1) time, O(1) space
 static bool Delete(LinkListNode n)
 {
     if (n.next == null || n == null)
         return false;
     else {
         n.data = n.next.data;
         n.next = n.next.next;
         return true;
     }
 }
Пример #3
0
 public LinkListNode clone()
 {
     LinkListNode next2 = null;
     if (next != null)
     {
         next2 = next.clone();
     }
     LinkListNode head2 = new LinkListNode(data, next2, null);
     return head2;
 }
Пример #4
0
        public LinkListNode clone()
        {
            LinkListNode next2 = null;

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

            return(head2);
        }
Пример #5
0
 public void setNext(LinkListNode n)
 {
     next = n;
     if (this == last)
     {
         last = n;
     }
     if (n != null && n.prev != this)
     {
         n.setPrevious(this);
     }
 }
Пример #6
0
 public void setNext(LinkListNode n)
 {
     next = n;
     if (this == last)
     {
         last = n;
     }
     if (n != null && n.prev != this)
     {
         n.setPrevious(this);
     }
 }
Пример #7
0
 //method 1: copy next node to n, delete next node, O(1) time, O(1) space
 static bool Delete(LinkListNode n)
 {
     if (n.next == null || n == null)
     {
         return(false);
     }
     else
     {
         n.data = n.next.data;
         n.next = n.next.next;
         return(true);
     }
 }
Пример #8
0
        //Delete middle node: Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node.
        static void Main(string[] args)
        {
            LinkListNode head = new LinkListNode(0);
            LinkListNode first = head;
            for(int i = 1; i < 10; i++){
                LinkListNode second = new LinkListNode(i);
                first.setNext(second);
                first = second;
            }

            Console.WriteLine(head.printForward());

            Delete(head.next.next.next.next.next);

            Console.WriteLine(head.printForward());
        }
Пример #9
0
    { //Delete middle node: Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node.
        static void Main(string[] args)
        {
            LinkListNode head  = new LinkListNode(0);
            LinkListNode first = head;

            for (int i = 1; i < 10; i++)
            {
                LinkListNode second = new LinkListNode(i);
                first.setNext(second);
                first = second;
            }

            Console.WriteLine(head.printForward());

            Delete(head.next.next.next.next.next);

            Console.WriteLine(head.printForward());
        }
Пример #10
0
 public LinkListNode(int d, LinkListNode n, LinkListNode p)
 {
     data = d;
     setNext(n);
     setPrevious(p);
 }
Пример #11
0
 public LinkListNode(int d, LinkListNode n, LinkListNode p)
 {
     data = d;
     setNext(n);
     setPrevious(p);
 }