struct ListNode
{
int val;
ListNode *next;
ListNode(int x =0) : val(x), next(NULL) {}
};
void ReverseList(ListNode ** head, ListNode* tail)
{
ListNode * p = *head;
ListNode * q = tail;
ListNode * n;
while( p != tail)
{
n = p->next;
p->next = q;
q = p;
p = n;
}
*head = q;
}
ListNode *ReverseNodesink_Group(ListNode *head, k)
{
ListNode ** h = &head;
ListNode * t = head;
ListNode * n = head;
while(1)
{
int count = k;
while(--count > 0 && t != NULL)
{
t = t->next;
}
if (t == NULL) break;
n = *h;
ReverseList(h, t->next);
h = &n->next;
t= n->next;
}
return head;
}