倒排链表
来源:互联网 发布:淘宝促销广告语大全 编辑:程序博客网 时间:2024/05/16 03:17
题目:
Node* reverse(Node* head)
{
if (head==NULL)
return head;
if(head->next==NULL) return head;
Node* ph=reverse(head->next);
head->next->next=head;
head->next=NULL;
return ph;
}
Node* reverseNonerecursive(Node* head)
{
if (head==NULL) return head;
Node* p=head;
Node* previous=NULL;
while(p->next!=NULL)
{
p->next=previous;
previous=p;
p=p->next;
}
p->next=previous;
return p;
}
0 0