odd_even_list

 public class Solution
{
    public ListNode OddEvenList(ListNode head)
    {
        if(head == null || head.next == null || head.next.next == null) return head;  //考虑特殊情况,0、1、2个点,直接返回
        ListNode res = head,a = head;          //a遍历奇数点  res记录奇数最开始的点
        ListNode bb=head.next,b = head.next;   //b遍历偶数点  bb 记录偶数最开始的点
        while (a.next != null && a.next.next !=null) {
            a.next = a.next.next;
            b.next = b.next.next;
            a = a.next;
            b = b.next;
        }
        if (a.next != null)
        {          
            b.next = null;
        }
        a.next = bb;
        return res;
    }
}

 

posted @ 2016-01-25 11:42  *桔子*  阅读(171)  评论(0编辑  收藏  举报