`
java-mans
  • 浏览: 11439571 次
文章分类
社区版块
存档分类
最新评论

【链表】将一个链表反转

 
阅读更多

typedef struct linknode

{

int data;

struct linknode *next;

}node;

//将一个链表逆置

node *reverse(node *head)

{

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

{

return 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;

}

typedef struct linknode

{

int data;

struct linknode *next;

}node;

//将一个链表逆置

node *reverse(node *head)

{

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

{

return 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;

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics