iterative太简单不写了

http://www.geeksforgeeks.org/write-a-function-to-reverse-the-nodes-of-a-linked-list/

 #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
#include <map>
#include <set>
using namespace std; struct node {
int data;
node *next;
node() : data(), next(NULL) { }
node(int d) : data(d), next(NULL) { }
}; void push(node* &head, int k) {
node *new_node = new node(k);
new_node->next = head;
head = new_node;
} void print(node *head) {
while (head) {
cout << head->data << " ";
head = head->next;
}
cout << endl;
} void reverselist(node *&head) {
if (!head) return;
node *cur = head;
node *next = head->next;
if (!next) return;
reverselist(next);
cur->next->next = cur;
cur->next = NULL;
head = next;
} int main() {
node *head = NULL;
push(head, );
push(head, );
push(head, );
push(head, );
push(head, );
print(head);
reverselist(head);
print(head);
return ;
}

Data Structure Linked List: Write a function to reverse a linked list的更多相关文章

  1. [转]Data Structure Recovery using PIN and PyGraphviz

    Source:http://v0ids3curity.blogspot.com/2015/04/data-structure-recovery-using-pin-and.html --------- ...

  2. [LeetCode] All O`one Data Structure 全O(1)的数据结构

    Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with va ...

  3. Leetcode: All O`one Data Structure

    Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with va ...

  4. Summary: Trie Data Structure

    Implement a Trie Data Structure, and search() & insert() function: we need to implement both Cla ...

  5. [leetcode]432. All O`one Data Structure全O(1)数据结构

    Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with va ...

  6. [Algorithm] Trie data structure

    For example we have an array of words: [car, done, try, cat, trie, do] What is the best data structu ...

  7. 面试总结之数据结构(Data Structure)

    常用数据结构及复杂度 http://www.cnblogs.com/gaochundong/p/3813252.html 常用数据结构的时间复杂度 Data Structure Add Find De ...

  8. [Algorithm] Heap data structure and heap sort algorithm

    Source, git Heap is a data structure that can fundamentally change the performance of fairly common ...

  9. [Algorithms] Tree Data Structure in JavaScript

    In a tree, nodes have a single parent node and may have many children nodes. They never have more th ...

随机推荐

  1. 一个RecycleView的强大adapter

    代码地址如下:http://www.demodashi.com/demo/12218.html 前言 一般我们要在mainActivity中利用RecycleView展示一个列表数据的时候,adapt ...

  2. 网络爬虫与搜索引擎优化(SEO)

    一.网络爬虫 网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本.另外一些不常使用的名字还有蚂蚁.自动索引. ...

  3. IOS开发准备 资料集锦

    1 http://blog.csdn.net/column/details/xfzl-kykhd.html 2

  4. DOM概念的区分:Attribute和Property, html()及.text(), .val()

    Attribute就是dom节点自带的属性 例如:html中常用的id.class.title.align等: <div id="immooc" title="慕课 ...

  5. mysql主从从

    1.从官网下载安装percona-xtrabackup2.xtrabackup只能备份和恢复innodb的表,所以这里用innobackupex,可以实现对myisam和innodb的表在线备份和恢复 ...

  6. windows 网站迁移到linux

    从windows迁移网站到linux 发现乱码 出现这种情况的原因为两种操作系统的中文压缩方式不同,在windows环境中中文一般为gbk,而在linux环境中为utf8,这就导致了在windows下 ...

  7. 转:什么是Node.js?

    Node不是万能药!但的确能解决一些关键问题 学习Node不是一件轻松事儿,但你所收到的回报是对得起你的付出的.因为当下Web应用开发中的诸多难题唯有JavaScript才能解决. 目录 专家们的警告 ...

  8. HDFS源码分析数据块校验之DataBlockScanner

    DataBlockScanner是运行在数据节点DataNode上的一个后台线程.它为所有的块池管理块扫描.针对每个块池,一个BlockPoolSliceScanner对象将会被创建,其运行在一个单独 ...

  9. python入门课程 第一章 课程介绍

    1-1 Python入门课程介绍特点:    优雅.明确.简单适合领域:    web网站和各种网络服务    系统工具和脚本    作为"胶水"语言把其他语言开发的模块包装起来方 ...

  10. 将非递减有序排列(L L1)归并为一个新的线性表L2 线性表L2中的元素仍按值非递减

    #include "stdio.h"#include "stdlib.h"#include "function.h"void main(){ ...