http://www.geeksforgeeks.org/reverse-a-list-in-groups-of-given-size/

 #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;
} node* reverselist(node *&head, int k) {
node *cur = head;
node *pre = NULL;
node *next;
int c = ;
while (cur && c < k) {
next = cur->next;
cur->next = pre;
pre = cur;
cur = next;
c++;
}
if (next) head->next = reverselist(next, k);
return pre;
} void print(node *head) {
while (head) {
cout << head->data << " ";
head = head->next;
}
} int main() {
node *head = NULL;
push(head, );
push(head, );
push(head, );
push(head, );
push(head, );
push(head, );
push(head, );
push(head, );
head = reverselist(head, );
print(head);
return ;
}

Data Structure Linked List: Reverse a Linked List in groups of given size的更多相关文章

  1. *Amazon problem: 234. Palindrome Linked List (reverse the linked list with n time)

    Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1->2 Output: false ...

  2. 【LeetCode】170. Two Sum III - Data structure design 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数组+字典 平衡查找树+双指针 日期 题目地址:htt ...

  3. 【LeetCode】9 & 234 & 206 - Palindrome Number & Palindrome Linked List & Reverse Linked List

    9 - Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. Som ...

  4. [Linked List]Reverse Nodes in k-Group

    Total Accepted: 48614 Total Submissions: 185356 Difficulty: Hard Given a linked list, reverse the no ...

  5. [Linked List]Reverse Linked List,Reverse Linked List II

    一.Reverse Linked List  (M) Reverse Linked List II (M) Binary Tree Upside Down (E) Palindrome Linked ...

  6. LeetCode之“链表”:Reverse Linked List && Reverse Linked List II

    1. Reverse Linked List 题目链接 题目要求: Reverse a singly linked list. Hint: A linked list can be reversed ...

  7. [Algorithm] Reverse a linked list

    It helps to understands how recursive calls works. function Node(val) { return { val, next: null }; ...

  8. [LeetCode] 92. Reverse Linked List II_Medium tag: Linked List

    Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Exa ...

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

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

随机推荐

  1. 命令行添加pod示例

    1.创建AlamFireDemo 工程,关闭工程 2.进入到工程目录 执行 pod init 命令 生成 PodFile文件 3.vi PodFile编辑该文件 启用:platform :ios, ' ...

  2. 打造Android万能上拉下拉刷新框架--XRefreshView(三)

    转载请注明出处:http://blog.csdn.net/footballclub/ 打造Android万能上拉下拉刷新框架–XRefreshView(一) 打造Android万能上拉下拉刷新框架–X ...

  3. Android API Guides---RenderScript

    RenderScript RenderScript是在Android上的高性能执行计算密集型任务的框架. RenderScript主要面向与数据并行计算的使用.尽管串行计算密集型工作负载能够受益.该R ...

  4. JDBC技术总结(一)

    1. JDBC简介 SUN公司为了简化.统一对数据库的操作,定义了一套Java操作数据库的规范,称之为JDBC,JDBC不能直接操作数据库,JDBC通过接口加载数据库的驱动,然后操作数据库.JDBC: ...

  5. Iterating elements using NightWatchJS

    1) used the following strategy to iterate over DOM elements using Nightwatch: // Executing a functio ...

  6. 转Python 标准库 urllib2 的使用细节

    Python 标准库中有很多实用的工具类,但是在具体使用时,标准库文档上对使用细节描述的并不清楚,比如 urllib2 这个 HTTP 客户端库.这里总结了一些 urllib2 库的使用细节. 1 P ...

  7. Spring Boot(六): Favicon配置

    1.默认的Favicon Spring Boot提供了一个默认的Favicon,每次访问应用的时候都能看到,如图所示. 2.关闭Favicon 我们可以在application.properties中 ...

  8. spring roo初体验

    1.下载spring-roo-2.0.0.M1,并执行如下命令,在/usr/local/bin下面建立一个roo的软连接   sudo ln -s /Users/pud/Documents/still ...

  9. CentOS 源码安装svn

    一. 下载依赖包 1. apr源码包 http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.5.2.tar.gz 2. apr-util源码包 h ...

  10. ubuntu 16.04中卸载软件。

    今天装了个QQ,结果不会用,折腾了半天终于卸载掉了. dpkg -l | grep qq(查出安装的软件) 使用 sudo dpkg --purge xxx(这里xxx写查出来的软件包名字)