Link List
At first, i prepared to go through 《the introduction to algorithm》 ,however , i found some part of the book is difficult to understand; what’s more , i can’t borrow the book in the library. Then i found another book, 《algorithm in C》,which reveal most basic idea of some classical algorithm, so i decide to read this book firstly.
example 1:josephus funciton
#include<stdlib.h>
#include<stdio.h>
typedef struct node* link;
struct node
{
int item;
link next;
}; int main(int argc,char *argv[])
{
int i, N, M;
scanf("%d%d",&N,&M);
node *t = new node,*x;
x = t;
t->item = 1;
t->next = t;
for (i = 2; i <= N; i++)
{
x->next = new node;
x = x->next;
x->item = i;
x->next = t;
}
while (x != x->next)
{
for (i = 1; i < M; i++)
{
x = x->next;
}
x->next = x->next->next;
N--;
}
printf("%d\n",x->item);
}
example2: reverse link list
#include<stdlib.h>
#include<stdio.h>
typedef struct node* link;
struct node
{
int item;
link next;
node()
{
next = NULL;
}
}; link reverse(link x)
{
/*
将y后节点的指针保存在t中,然后将y的链接指向r,再使r移到y,y移到t
*/
link t, y = x, r = NULL;
while (y != NULL)
{
t = y->next;
y->next = r;
r = y;
y = t;
}
return r;
} int main(int argc,char *argv[])
{
int i, N, M;
scanf("%d%d",&N,&M);
node *t = new node,*x,*head;
x = t;
head = t;
t->item = 1;
t->next = t;
for (i = 2; i <= N; i++)
{
x->next = new node;
x = x->next;
x->item = i;
}
node *newhead = reverse(head);
while (newhead != NULL)
{
printf("%d ",newhead->item);
newhead = newhead->next;
}
}
Link List的更多相关文章
- oracle db link的查看创建与删除
1.查看dblink select owner,object_name from dba_objects where object_type='DATABASE LINK'; 或者 select * ...
- 解决Java程序连接mysql数据库出现CommunicationsException: Communications link failure错误的问题
一.背景 最近在家里捣鼓一个公司自己搭建的demo的时候,发现程序一启动就会出现CommunicationsException: Communications link failure错误,经过一番排 ...
- 解决绝对定位div position: absolute 后面的<a> Link不能点击
今天布局的时候,遇到一个bug,当DIV设置为绝对定位时,这个div后面的相对定位的层里面的<a>Link标签无法点击. 网上的解决方案是在绝对定位层里面添加:pointer-events ...
- LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
同时安装了VS2012和VS2010,用VS2010 时 >LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏 问题说明:当安装VS2012之后 ...
- VS2013的 Browser Link 引起的问题
环境:vs2013 问题:在调用一个WebApi的时候出现了错误: 于是我用Fiddler 4直接调用这个WebApi,状态码是200(正常的),JSon里却提示在位置9409处文本非法, 以Text ...
- angular中的compile和link函数
angular中的compile和link函数 前言 这篇文章,我们将通过一个实例来了解 Angular 的 directives (指令)是如何处理的.Angular 是如何在 HTML 中找到这些 ...
- AngularJS之指令中controller与link(十二)
前言 在指令中存在controller和link属性,对这二者心生有点疑问,于是找了资料学习下. 话题 首先我们来看看代码再来分析分析. 第一次尝试 页面: <custom-directive& ...
- Visual Studio 2013中因SignalR的Browser Link引起的Javascript错误一则
众所周知Visual Studio 2013中有一个由SignalR机制实现的Browser Link功能,意思是开发人员可以同时使用多个浏览器进行调试,当按下IDE中的Browser Link按钮后 ...
- link与@import的区别
我们都知道link与@import都可以引入css样式表,那么这两种的区别是什么呢?先说说它们各自的链接方式,然后说说它们的区别~~~ link链入的方式: <link rel="st ...
- 错误提示:LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt 的解决方法
最近在win7 系统下,打算利用 cmake 生成项目文件,然后用vs2010进行编译.但是在cmake的时候出现错误弹窗:
随机推荐
- <转>Python运行的17个时新手常见错误小结
1)忘记在 if , elif , else , for , while , class ,def 声明末尾添加 :(导致 “SyntaxError :invalid syntax”) 该错误将发生在 ...
- 白盒测试之gmock入门篇
一.gmock是什么 gmock是google公司推出的一款开源的白盒测试工具.gmock是个很强大的东西,测试一个模块的时候,可能涉及到和其他模块交互,可以将模块之间的接口mock起来,模拟交互过程 ...
- bzoj 3143 [Hnoi2013]游走(贪心,高斯消元,期望方程)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3143 [题意] 给定一个无向图,从1走到n,走过一条边得到的分数为边的标号,问一个边的 ...
- Nodejs与Net 和SQL 交互利器Edge.js
https://github.com/tjanczuk http://www.cnblogs.com/joylee/archive/2013/02/05/msnodesql.html edge.js这 ...
- 现代程序设计 homework-07
现代程序设计 homework-07 这次作业是要阅读C++11的新特性,按照老师blog提供的链接稍微学习了一下,一下就是一些学习总结(或者说就是介绍)之类的:由于英文能力有限,并且很多中文资料也都 ...
- Spring EL hello world example
The Spring EL is similar with OGNL and JSF EL, and evaluated or executed during the bean creation ti ...
- thymeleaf条件表达式
条件表达式形式:condition, then and else <tr th:class="${row.even}? 'even' : 'odd'"> ... < ...
- uva 10274 Fans and Gems(隐式图搜索+模拟)
Fans and Gems Input: Standard Input Output: Standard Output Tomy's fond of a game called 'Fans and G ...
- HDU 4597 Play Game (DP,记忆化搜索,博弈)
题意:Alice和Bob玩一个游戏,有两个长度为N的正整数数字序列,每次他们两个,只能从其中一个序列,选择两端中的一个拿走.他们都希望可以拿到尽量大的数字之和, 并且他们都足够聪明,每次都选择最优策略 ...
- Windows下sqlmap的使用_01
环境:win8.1 64位 一.下载 首先,需下载SqlMap以及适用于Windows系统的Python.下载地址如下: 1.1.SqlMap下载地址:https://github.com/ ...