首页 > 试题广场 >

完成使链表逆置函数reverse,若有链表:

[问答题]

完成使链表逆置函数reverse,若有链表:

链表结点的结构如下:
struct node
{
int num;
struct node *next;
}
struct node* reverse(struct node *head)
//head 链表头结点
{
struct node *p,*temp1,*temp2;
if(head==NULL____①____) return head; //
||head->next==NULL
p=head->next;head->next=NULL;
while(____②____) //
p!=NULL或p
{
temp1=head;
____③____; //
head=p;
temp2=p;
p=p->next;
____④____; //
temp2->next=temp1;或head->next=temp1;
}//Match while statenment
return head; //返回逆置后的链表的头结点
}


这道题你会答吗?花几分钟告诉大家答案吧!