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 ;
}

最新文章

  1. UITableViewCell 的附件类型 accessoryType 选中、详情、箭头
  2. 浮点数 (IEEE-754)
  3. HashMap,LinkedHashMap,TreeMap的区别
  4. 使用sql更改表的列的数据类型和添加新列和约束
  5. css3 transition属性变化与animation动画的相似性以及不同点
  6. PHP中使用CURL实现GET和POST请求
  7. 2016 系统设计第一期 (档案一)MVC a标签 跳转 Html.ActionLink的用法
  8. ~/.bashrc的常用alias设置
  9. StringBuffer类的使用
  10. (文件)图片上传,Spring或SpringMVC框架
  11. Cordova各个插件使用介绍系列(六)—$cordovaDevice获取设备的相关信息
  12. C#上位机串口控制12864显示
  13. Technical debt
  14. heartbeat单独提供高可用服务
  15. 《Effective Objective-C 2.0》摘要
  16. Sql Server 字符串操作总结
  17. [原]Docker-issue(1) image name 显示为 &lt;none&gt;
  18. SQL类型转换和数学函数
  19. NET设计模式 第二部分 结构性模式(9):装饰模式(Decorator Pattern)
  20. 【API规范】OpenAPI规范

热门文章

  1. 基于RxJava2+Retrofit2精心打造的Android基础框架
  2. 通过rinetd实现端口转发,同时访问阿里云RDS的内外网
  3. Storm/Cassandra集成错误:NoSuchMethodError: concurrent.Futures.withFallback
  4. Android中多线程编程(三)Handler更新UI的方式
  5. org.mockito.exceptions.misusing.MissingMethodInvocationException: when() requires an argument which has to be &#39;a method call on a mock&#39;
  6. Unix编程第7章 进程环境
  7. Google Code Jam 2014 资格赛:Problem B. Cookie Clicker Alpha
  8. Crashing Robots - poj 2632
  9. Java并发:等待事件发生后所有线程继续执行
  10. Gradle 的配置和引用