Data Structure Linked List: Write a function to reverse a linked list
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的更多相关文章
- [转]Data Structure Recovery using PIN and PyGraphviz
Source:http://v0ids3curity.blogspot.com/2015/04/data-structure-recovery-using-pin-and.html --------- ...
- [LeetCode] All O`one Data Structure 全O(1)的数据结构
Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with va ...
- Leetcode: All O`one Data Structure
Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with va ...
- Summary: Trie Data Structure
Implement a Trie Data Structure, and search() & insert() function: we need to implement both Cla ...
- [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 ...
- [Algorithm] Trie data structure
For example we have an array of words: [car, done, try, cat, trie, do] What is the best data structu ...
- 面试总结之数据结构(Data Structure)
常用数据结构及复杂度 http://www.cnblogs.com/gaochundong/p/3813252.html 常用数据结构的时间复杂度 Data Structure Add Find De ...
- [Algorithm] Heap data structure and heap sort algorithm
Source, git Heap is a data structure that can fundamentally change the performance of fairly common ...
- [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 ...
随机推荐
- Vue-cli + Express 构建的SPA Blog(前后分离)
代码地址如下:http://www.demodashi.com/demo/12526.html 为什么学习并使用Vue 1.发展趋势 最近这几年的前端圈子,由于戏台一般精彩纷呈,从 MVC 到 MVV ...
- 一个RecycleView的强大adapter
代码地址如下:http://www.demodashi.com/demo/12218.html 前言 一般我们要在mainActivity中利用RecycleView展示一个列表数据的时候,adapt ...
- go http请求基础
1.请求方法: get post get 加请求参数,请求参数会加到url后面 post加请求参数,请求参数会放在body里面 请求方式:1.直接在url后面加参数 如:http://www.tes ...
- Machine Learning——Unsupervised Learning(机器学习之非监督学习)
前面,我们提到了监督学习,在机器学习中,与之对应的是非监督学习.无监督学习的问题是,在未加标签的数据中,试图找到隐藏的结构.因为提供给学习者的实例是未标记的,因此没有错误或报酬信号来评估潜在的解决方案 ...
- Atitit.跨语言 java c#.net php js常用的codec encode算法api 兼容性 应该内置到语言里面
Atitit.跨语言 java c#.net php js常用的codec encode算法api 兼容性 应该内置到语言里面 1. 常用算法1 1.1. 目录2 1.2. 定义和用法编辑2 1.3 ...
- HTML5 2D平台游戏开发#8指令技
一般在动作游戏中,玩家可以通过对输入设备输入一系列的指令让角色完成某个或多个特定的动作.以格斗游戏<拳皇>为例,键入↓↘→↘↓↙← + A or C可以触发IORI的必杀技八稚女: 通过一 ...
- 50条SQL查询技巧、查询语句示例
学习了 1.查询“001”课程比“002”课程成绩高的所有学生的学号: 2.查询平均成绩大于60分的同学的学号和平均成绩: 3.查询所有同学的学号.姓名.选课数.总成绩: 4.查询姓“李”的老师的个数 ...
- 各种类型的电影排行榜-movie路线
[最费脑力的14部电影]<盗梦空间>.<记忆裂痕>.<生死停留>.<死亡幻觉>.<禁闭岛>.<穆赫兰道>.<蝴蝶效应> ...
- ios 推送 证书配置
S的推送证书,有有效期限制,一般为一年.当我们证书过期的时候,就需要重新生成证书了.有一段时间没有上苹果网站了,昨天上去一看,此奥,改版了,下边我们将重新生成一个正式环境的push推送的证书. 1.先 ...
- python利用正则表达式提取字符串
前言 正则表达式的基础知识就不说了,有兴趣的可以点击这里,提取一般分两种情况,一种是提取在文本中提取单个位置的字符串,另一种是提取连续多个位置的字符串.日志分析会遇到这种情况,下面我会分别讲一下对应的 ...