Data Structure Linked List: Reverse a Linked List in groups of given size
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的更多相关文章
- *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 ...
- 【LeetCode】170. Two Sum III - Data structure design 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数组+字典 平衡查找树+双指针 日期 题目地址:htt ...
- 【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 ...
- [Linked List]Reverse Nodes in k-Group
Total Accepted: 48614 Total Submissions: 185356 Difficulty: Hard Given a linked list, reverse the no ...
- [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 ...
- LeetCode之“链表”:Reverse Linked List && Reverse Linked List II
1. Reverse Linked List 题目链接 题目要求: Reverse a singly linked list. Hint: A linked list can be reversed ...
- [Algorithm] Reverse a linked list
It helps to understands how recursive calls works. function Node(val) { return { val, next: null }; ...
- [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 ...
- [转]Data Structure Recovery using PIN and PyGraphviz
Source:http://v0ids3curity.blogspot.com/2015/04/data-structure-recovery-using-pin-and.html --------- ...
随机推荐
- Oracle 查询用户表信息,导入导出处理表空间不一致
select table_name,tablespace_name from user_tables t; //查询用户默认表空间信息 SELECT t.* FROM USER_USERS t; 导入 ...
- spring aop中的propagation(传播属性)的7种配置的意思
1.前言. 在声明式的事务处理中,要配置一个切面,即一组方法,如 <tx:advice id="txAdvice" transaction-manager="t ...
- Loadrunner中对中文进行UTF-8转码的探索
上一篇 / 下一篇 2010-02-22 15:20:28 查看( 2378 ) / 评论( 2 ) / 评分( 5 / 0 ) 这是一个HTTP接口测试中经常会碰到的问题,目前的服务器采用的都是U ...
- zabbix客户端安装shadowscoks客户端监控访问google网站
配置zabbix客户端配置文件 vim /etc/zabbix/zabbix_agentd.conf 添加 Include=/etc/zabbix/zabbix_agentd.d/ 添加脚本探测访问 ...
- MongoDB查询条件常用设置
原文地址:http://blog.csdn.net/mcpang/article/details/8731065 Java操作mongodb进行查询,常用筛选条件的设置如下: 条件列表: BasicD ...
- 高抛低吸T+0操作要领(目前行情短线炒作的必备技能)
最近的行情只能用操蛋来形容,但是危机中不乏机会.现在已经不是之前行情的思路,那着一个股票长线抱着,即使是好的牛股,也经不起目前行情的这 么折腾.所以,现在最适合的操作方式就是高抛低吸.今天低吸保不准明 ...
- Eclipse个最实用的快捷键
一个Eclipse骨灰级开发人员总结了他觉得最实用但又不太为人所知的快捷键组合.通过这些组合能够更加easy的浏览源码,使得总体的开发效率和质量得到提升. 1. ctrl+shift+r:打开 ...
- codeforces #364d As Fast As Possible
题意:一群学生,要到离这里为l的地方去.有一辆车,车只有k个座位.人和车的速度分别v1,v2,问你所有人到达的最小时间. 思路:数学题.最小时间就是要求所有同学同时到达.每个同学最多上一次车.那么显然 ...
- 查看Android源码和源码布局
一.查看源码 1.https://github.com/android 2.http://grepcode.com/project/repository.grepcode.com/java/ext/c ...
- maven 常用的环境插件
<build> <finalName>yycgproject</finalName> <plugins> <!-- 修改jdk插件 --> ...