标签:
#include <map>
#include <iostream>
#include <vector>
using namespace std;
struct ListNode {
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
};
class Solution {
public:
ListNode* oddEvenList(ListNode* head) {
if (head == NULL)
return head;
ListNode *odd = head, *even = head->next, *evenhead = even;
while (even&&even->next)
{
odd->next = odd->next->next;
even->next = even->next->next;
odd = odd->next;
even = even->next;
}
odd->next = evenhead;
while (head)
{ cout << head->val << endl;
head = head->next;
}
return head;
}
};
int main()
{
ListNode a = 1;
ListNode b = 2;
ListNode c = 3;
ListNode d = 4;
ListNode e = 5;
a.next = &b;
b.next = &c;
c.next = &d;
d.next = &e;
e.next = NULL;
Solution A;
A.oddEvenList(&a);
}
标签:
原文地址:http://www.cnblogs.com/-vector/p/5183002.html