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. 类中的internal成员可能是一种坏味道

    前言 最近除了搞ASP.NET MVC之外,我也在思考一些编程实践方面的问题.昨天在回家路上,我忽然对一个问题产生了较为清晰的认识.或者说,原先只是有一丝细微的感觉,而现在将它和一些其他的方面进行了联 ...

  2. 征信报告页面的input验证收集

    https://ipcrs.pbccrc.org.cn/ function checkLoginName() { var loginName = $.trim($("#loginname&q ...

  3. 常用IIS mime类型

    MIME类型 .woff font/x-woff.json application/json.svgz image/svg+xml .ttf application/octet-stream.eot ...

  4. Android应用架构之MVP---&gt;天气实例

    我们知道.Android App 本质上抽象成两个层次:视图和数据.为了App在发展过程中高速的适应变化,方便维护和高速迭代,我们要将数据和视图解耦,而在解藕方面我们的前辈们在漫长的软件开发经验中为我 ...

  5. 看完这篇还不会 GestureDetector 手势检测,我跪搓衣板!

    引言 在 android 开发过程中,我们经常需要对一些手势,如:单击.双击.长按.滑动.缩放等,进行监测.这时也就引出了手势监测的概念,所谓的手势监测,说白了就是对于 GestureDetector ...

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

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

  7. 解决Apache长时间占用内存大的问题,Apache 内存优化方法

    问:为什么服务器在连续运行多天后或访问峰值后,进程中的一个Apache.exe占用内存几百兆不减少?答:用记事本打开apache2\conf\httpd.conf,我在centos5上装了kloxo, ...

  8. Spring WebSocket Support官方文档+翻译

    实时更新技术能够应用在很多场景中,比如在浏览器中聊天.股票报价.状态更新.现场直播.这些需求对时间的延迟性都很敏感,但是我们可以发现他们存在这共有的共性. 标准的HTTP请求,是一次请求对应一次相应. ...

  9. IE下object元素遮挡div表单

    目前遇到这样的一个问题: 我用ActiveX插件做了一个C#的播放器,要将这个插件放到web浏览器中,然后可以通过前台页面来控制视频的播放,暂停还有回放,这个时候发现object的onclick事件无 ...

  10. 利用github Pages和Jekyll搭建blog实践1

    你必须要懂一点git和网页开发.安装了git,并且有github账户. github设计了Pages功能,允许用户自定义项目首页 github提供模板,允许站内生成网页,但也允许用户自己编写网页,然后 ...