剑指offer 16- 反转链表
来源:互联网 发布:mac无苹果安装win7系统 编辑:程序博客网 时间:2024/05/19 00:39
#include <iostream>#include <stack>using namespace std;//无头节点struct ListNode{int m_nValue;ListNode* m_pNext;};void InsertListNode( ListNode **head, int value) { ListNode* p= new ListNode(); p->m_nValue = value; p->m_pNext = NULL; if (*head == NULL) { *head = p; } else { ListNode* node = *head; while(node->m_pNext != NULL) node = node->m_pNext; node->m_pNext = p; } }ListNode * ReverseListNode(ListNode *head){ListNode * p=NULL;ListNode *pNext=NULL; while(head != NULL){pNext = head->m_pNext;head->m_pNext = p;p = head;head = pNext;}return p;}void printListNode(ListNode * node){while(node!=NULL){cout<<node->m_nValue <<" ";node = node->m_pNext;} cout<<endl;}int main(int argc, char* argv[]){ListNode *head = NULL;int a[]= {1,2,3,4,5};for(int i=0;i<sizeof(a)/sizeof(int);i++){ InsertListNode( &head,a[i]);}printListNode(head);head = ReverseListNode(head);printListNode(head);head = ReverseListNode(NULL); //空指针printListNode(head); return 0;}
0 0
- 剑指offer 16- 反转链表
- 16链表的反转|剑指offer
- 剑指Offer 16 反转链表
- 剑指offer-16:反转链表
- 【剑指offer】题16:反转链表
- 剑指offer面试16 反转链表
- 剑指offer 16 反转链表
- 剑指offer:反转链表
- 剑指offer--反转链表
- 剑指offer--反转链表
- 剑指Offer-反转链表
- 《剑指offer》反转链表
- 剑指 offer:反转链表
- 剑指offer-反转链表
- 剑指offer 反转链表
- 剑指offer-反转链表
- 剑指offer:反转链表
- [剑指offer]反转链表
- 25个git进阶技巧
- SQLite3中自增主键归零方法
- Eclipse TestNG
- apt-get常用命令
- 关于字符串能不能修改,重指向的问题解释
- 剑指offer 16- 反转链表
- 西安治疗纤维瘤去哪个医院
- openssl入门编程
- Vijos-P1097-合并果子(简单贪心 && 优先队列 && c++)
- 逼真黑客范儿–Hacker Typer
- php创建接口出现乱码 encode urldecode转换程字符串
- ExtJs学习
- 一个菜鸟的Windows Phone开发日志
- init/main.c源码分析