Exemple #1
0
 private static void PrintList(MyLinkList link)
 {
     MyLinkList t = link;
     while (t != null)
     {
         Console.Write("" + t.val + " ");
         t = t.next;
     }
 }
Exemple #2
0
        static void Main(string[] args)
        {
            MyLinkList link = new MyLinkList(1);
            link.next = new MyLinkList(2);
            link.next.next = new MyLinkList(3);
            link.next.next.next = new MyLinkList(4);
            link.next.next.next.next = new MyLinkList(5);
            PrintList(link);

            MyLinkList newHead= RotateLinkList(link, 3);
            PrintList(newHead);
            Console.ReadKey();
        }
Exemple #3
0
 private static MyLinkList RotateLinkList(MyLinkList link, int p)
 {
     MyLinkList t = link;
     while (p != 0)
     {
         t = t.next;
         p--;
         if (t == null)
             return null;
     }
     //Set new head
     MyLinkList newHead = t.next;
     // Set t.next = null to make it end of list
     t.next = null;
     MyLinkList newHeadTemp = newHead;
     while (newHeadTemp.next != null)
     {
         newHeadTemp = newHeadTemp.next;
     }
     newHeadTemp.next = newHead;
     return newHead;
 }
Exemple #4
0
 public MyLinkList(int a)
 {
     val = a;
     next = null;
 }