轩辕

运筹帷幄世界在我手中!

导航

单链的逆置

node *reverse(node *head)

{

node *p1,*p2,*p3;

if(head==NULL||head->next==NULL)

return head;

p1=head,p2=p1->next;

while(p2)

{

p3=p2->next;

p2->next=p1;

p1=p2;

p2=p3;

}

head->next=NULL;

head=p1;

return head;

}

int main()

{

node *head,stud;

int n,del,num,insert_num;

head=create();

print(head);

cout<<"\nInt:";

cin>>del_num;

head=del(head,del_num);

print(head);

cin>>insert_num;

head=insert(head,insert num);

print(head);

return 0;

}

posted on 2013-02-23 12:10  峻华  阅读(110)  评论(0)    收藏  举报