试写一算法,对单链表实现就地逆置。数据结构的题目(C语言版的)

2024-12-27 00:48:49
推荐回答(1个)
回答1:

算法已经写清楚了,里面的first 就是你传入的hlink

template
void mylist::Invert()//翻转
{
if ( IsNull() || ncount == 1) return;
listnode* m,* n;
m = first;
while (m!=NULL)
{
listnode* r = n;
n = m;
m = m->link;
n->link = r;
}
first = n;
}