剑指Offer——面试题24:反转链表

面试题24:反转链表
题目:定义一个函数,输入一个链表的头结点,反转该链表并输出反转后链表的头结点。
在这里插入图片描述

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
struct ListNode{
	int value;
	ListNode* next;
};
ListNode* ReverseList(ListNode* pHead){
	ListNode* pReversedHead=NULL;
	ListNode* pNode=pHead;
	ListNode* pPrev=NULL;
	while(pNode!=NULL){
		ListNode* pNext=pNode->next;
		if(pNext==NULL) pReversedHead=pNode;
		pNode->next=pPrev;
		pPrev=pNode;
		pNode=pNext;
	}
	return pReversedHead;
}
int main() {
	
	return 0;
}
发布了42 篇原创文章 · 获赞 43 · 访问量 1068

猜你喜欢

转载自blog.csdn.net/qq_35340189/article/details/104402065