当前位置:才华君>好好学习>考研>

写出程序把一个链表中的接点顺序倒排

考研 阅读(2.55W)

typedef struct linknode

写出程序把一个链表中的接点顺序倒排

{

int data;

struct linknode *next;

}node;

//将一个链表逆置

node *reverse(node *head)

{

node *p,*q,*r;

p=head;

q=p->next;

while(q!=NULL)

{

r=q->next;

q->next=p;

p=q;

q=r;

}

head->next=NULL;

head=p;

return head;

}