奇偶链表
1 package algorithms; 2 3 public class Exp5_2 { 4 //画图解决 5 public ListNode oddEvenList(ListNode head) { 6 if (head == null) 7 return null; 8 ListNode pOddNode = head; 9 ListNode pEvenNode = head.next; 10 ListNode pOddTail = head; 11 while (pEvenNode != null) { 12 pOddNode = pEvenNode.next; 13 if(pOddNode==null) 14 break; 15 pEvenNode.next = pOddNode.next; 16 pOddNode.next = pOddTail.next; 17 pOddTail.next = pOddNode; 18 pOddTail = pOddTail.next; 19 pEvenNode = pEvenNode.next; 20 21 } 22 return head; 23 24 } 25 }