标签:bre while 单向链表 list use printf == str 翻转
#include <stdio.h> #include <stdlib.h> typedef struct ListNode { int val; struct ListNode *next; }ListNode; ListNode* ReverseList(ListNode* pHead) { if (pHead == NULL) return pHead; ListNode* pre = NULL; ListNode* cur = pHead; ListNode* nxt = NULL; ListNode* res = NULL; while (cur != NULL) { nxt = cur->next; cur->next = pre; if (nxt == NULL) break; pre = cur; cur = nxt; } return cur; } int main() { int i = 0; ListNode *pHead = NULL; while (i <= 5) { ListNode *pNew = (ListNode *)malloc(sizeof(ListNode)); pNew->val = i++; pNew->next = pHead; pHead = pNew; } pHead = ReverseList(pHead); while (pHead) { printf("%d ", pHead->val); pHead = pHead->next; } system("pause"); return 0; }
标签:bre while 单向链表 list use printf == str 翻转
原文地址:https://www.cnblogs.com/veis/p/12623112.html