链表逆置

 

struct ListNode *reverse(struct ListNode *head)
{
if(head==NULL||head->next==NULL)
{
return head;
}
struct ListNode *p=NULL,*t,*pp=head;
while(pp)
{
t=pp->next;
pp->next=p;
p=pp;
pp=t;
}
return p;
}

posted @ 2023-11-17 11:29  涨涨涨张  阅读(5)  评论(0编辑  收藏  举报