|
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node * next;
}*head;
struct node * newnode()
{
return (struct node *)malloc(sizeof(struct node));
}
void view()
{
struct node *p=head;
while(p)
{
printf("%3d",p->data);
p=p->next;
}
}
void relist()/*链表倒置*/ {
struct node *p1,*p2,*p3;
p1=head; p2=p1->next; p3=p2->next; p1->next =NULL;
while(p3) { p2->next =p1; p1=p2; p2=p3; p3=p3->next ; }
p2->next =p1;head=p2;} void main() { struct node *p1,*p2; int i; head=newnode(); p1=head; head->data=0; head->next=NULL; for(i=1;i<=10;i++) { p2=newnode(); p2->data=i; p2->next =NULL; p1->next=p2; p1=p2; } view(); printf("n"); relist(); view(); }
(编辑:安卓应用网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|