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
    {//return kth to last: implement an algorithm to find the kth to last elment of a single linked list. 

        static void Main(string[] args)
        {
            //need test later
            
            LinkListNode first = new LinkListNode(0, null, null); 
            LinkListNode head = first;
            LinkListNode second = first;
            for (int i = 1; i < 7; i++)
            {
                second = new LinkListNode(i, null, null);
                first.setNext(second);
                second.setPrevious(first);
                first = second;
            }
      
            for (int i = 0; i <= 7 + 1; i++)
            {
                //Console.WriteLine(kthToLastEleTwoPointer(head, i).data);
                LinkListNode node = kthToLastEle(head, i);
                String nodeValue = node == null ? "null" : "" + node.data;
                Console.WriteLine(nodeValue);
            }
        }
Ejemplo n.º 4
0
        //return kth to last: implement an algorithm to find the kth to last elment of a single linked list.
        static void Main(string[] args)
        {
            //need test later

            LinkListNode first = new LinkListNode(0, null, null);
            LinkListNode head = first;
            LinkListNode second = first;
            for (int i = 1; i < 7; i++)
            {
                second = new LinkListNode(i, null, null);
                first.setNext(second);
                second.setPrevious(first);
                first = second;
            }

            for (int i = 0; i <= 7 + 1; i++)
            {
                //Console.WriteLine(kthToLastEleTwoPointer(head, i).data);
                LinkListNode node = kthToLastEle(head, i);
                String nodeValue = node == null ? "null" : "" + node.data;
                Console.WriteLine(nodeValue);
            }
        }