单链表指针反向(即链表地址逆转)

//head为原始链表的头节点地址
listNode *buf = head;
listNode *pre = buf;
while(head->next != NULL)
{

  buf = head->next;
  head->next = buf->next;
  buf->next = pre;
  pre = buf;

}

//该段代码结束后,buf变成了头节点,head变成了尾节点

posted on 2018-03-07 16:31  HelloShijam  阅读(237)  评论(0编辑  收藏  举报

导航