作业:实现双向链表的逆置
代码:
/*
* function: 逆置
* @param [ in]
* @param [out]
* @return 返回地址
*/
DoubleLink rev_Linklist(DoubleLink L)
{
//判断链表是否为空,判断链表是否只有一个节点
if (NULL == L || L -> next == NULL)
{
return L;
}
//链表有多个节点
DoubleLink p = L -> next;
int len = len_Linklist(L) - 1;
L -> next = NULL;
for (int i = 0; i < len; i++)
{
DoubleLink t = p;
p = p -> next;
t -> prev = NULL;
t -> next = L;
L -> prev = t;
L = t;
output(L);
}
return L;
}
结果:
思维导图