void K_Reverse( List L, int K )
{ //此题已经默认size >= K 因为当size < K时 反转后将不再符合链表的定义
//求出表中元素个数
int size = 0;
for (List cur = L->Next; cur != NULL; cur = cur->Next)
size++;
List prv, cur, next, first, head = L;
//共需要反转 size/K 轮
for (int i = 1; i <= size / K; i++)
{
//每轮需要反转K-1次[每两个结点间记作一次]
int j = K - 1;
prv = head -> Next;
cur = prv-> Next;
first = prv;
while(j--)
{
next = cur -> Next;
cur -> Next = prv;
prv = cur;
cur = next;
}
head -> Next = prv;
first -> Next = cur;
//下一轮的哨兵位即下一轮的首结点的上一个
//即上一轮的最后一个结点
head = first;
}
}