标签:
#include<iostream> #include<stack> using namespace std; struct ListNode { ListNode *next; int data; ListNode(int x): { data=x; next=NULL: } }; ListNode* ReverseList(ListNode* pHead) { if(pHead==NULL||pHead->next == NULL) { return pHead; } ListNode * p=pHead; ListNode * newHead; stack<ListNode *> stack1; while(p->next!=NULL) { stack1.push(p); p=p->next; } newHead = p; while(!stack1.empty()) { p->next=stack1.top(); p=p->next; stack1.pop(); } p->next=NULL; return newHead; } int mian() { struct ListNode *head; ReserveList(head); return 0; }
标签:
原文地址:http://blog.csdn.net/yangshuangtao/article/details/46634959