链表反序,设有数据结构 typedef struct _list_node { double keyVal; struct _list_node *next; }ListNode; ListNode* reverseList(ListNode* head) { ListNode *p1, *p2 , *p3; //链表为空,或是单结点链表直接返回头结点 if (head == NULL || head->next == NULL) { return head; } p1 = head; p2 = head->next; while (p2 != NULL) { p3 = p2->next; p2->next = p1; p1 = p2; p2 = p3; } head->next = NULL; head = p1; return head; }
温馨提示:内容为网友见解,仅供参考