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. 定制一个类似地址选择器的view

    代码地址如下:http://www.demodashi.com/demo/12832.html 前言: 这几天也是闲来无事,看看有什么和Scroller相关的控件需要巩固下,原因很简单,前几天看到相关 ...

  2. 02-1设置第一启动项--电脑怎么进入BIOS的方法集合

    电脑怎么进入BIOS的方法集合 很多时候为了对电脑进行相关设置,我们必须进入电脑的bios界面,但是不同的电脑进入bios的方法各不相同,小编今天就在这儿将各种电脑进入bios的方法汇总一下,希望对你 ...

  3. nightwatchJS ---element用法

    .element() Search for an element on the page, starting from the document root. The located element w ...

  4. Mongodb基本操作入门,增删改查和索引

    主要进程 mongod.exe为启动数据库实例的进程. mongo是一个与mongod进程进行交互的JavaScript shell进程,它提供了一些交互的接口函数用户对数据库的管理. 基本命令 sh ...

  5. surface4 笔盖失灵的解决方案

    http://tieba.baidu.com/p/3670357234 先找到设备管理器,找到蓝牙,删除里面所有的设备.然后重启. 之后再次找到蓝牙,匹配pen.就可以用了. 解决的前提是:我确定笔帽 ...

  6. 模拟和数字低通滤波器的MATLAB实现

    低通滤波器参数:Fs=8000,fp=2500,fs=3500,Rp=1dB,As=30dB,其他滤波器可以通过与低通之间的映射关系实现. %%模拟滤波器 %巴特沃斯——滤波器设计 wp=2*pi*2 ...

  7. How to Use HTML5 FUll Screen API(怎样使用HTML5全屏接口)

    原文链接:http://www.sitepoint.com/use-html5-full-screen-api/ 假设你不太喜欢变化太快的东西,那么web开发可能不适合你. 我曾在2012年末有写过F ...

  8. ListView中CheckBox使用问题

    因为CheckBox的点击事件优先级比ListView的高,所以当ListView中使用CheckBox会导致ListView的setOnItemClickListener失去响应. 解决的方法:在C ...

  9. IIS 实现一个主机部署多个网站 共享80端口

    如果一个主机只是建立一个80端口的网站就有点浪费了,通过本文你就可以实现,在一个主机上建立多个80端口的站点,并通过不同的域名进行访问. 打开iis软件:控制面板-->管理工具-->Int ...

  10. Auto Layout之创建布局约束

    上篇文章给大家介绍了AutoLayout 的由来及OC中关于AutoLayout 的类.这篇文章将向大家介绍,在iOS 编程中怎样使用Auto Layout 构建布局约束. 创建布局约束 创建布局约束 ...