单链表的插入操作实现

 #include <stdio.h>
#include <stdlib.h> typedef struct LinkList
{
int data;
struct LinkList *next;
}LinkList; void CreateLinkList(LinkList *&L,int n, int *array)
{
L =(LinkList*)malloc(sizeof(LinkList)); //先创建一个带头结点的单链表
L->next = NULL;
LinkList * r = L; //r指针始终指向链表的最后一个节点
for (int i = ; i < n; ++i)
{
LinkList * p =(LinkList*)malloc(sizeof(LinkList));
p->data = *array++;
//将新增的节点用尾插法插入到链表中
p->next = r->next;
r->next = p;
r = p;
} } void InsertLinkList(LinkList *&L, int n, int item, int data)
{
if(item > n || item < )
{
printf("error!");
exit(-);
}
else
{
LinkList *p = L;
for (int i = ; i < item-; ++i)
{
p = p->next;
} LinkList * node =(LinkList*)malloc(sizeof(LinkList));
node->data = data;
node->next = p->next;
p->next = node;
}
} void DisLinkList(LinkList *L)
{
LinkList *p = L->next;
while(p!=NULL)
{
printf("%d ",p->data);
p = p->next;
}
} int main(int argc, char const *argv[])
{
/*int n = 5;
int arry[]={1,2,3,4,5};
int item = 3;
int data = 6;*/ int n,item,data;
int *arry; scanf("%d",&n);
arry = (int*)malloc(n*sizeof(int));
for (int i = ; i < n; ++i)
{
scanf("%d",&arry[i]);
}
scanf("%d",&item);
scanf("%d",&data); LinkList * L;
CreateLinkList(L,n,arry);
InsertLinkList(L,n,item,data);
DisLinkList(L);
return ;
}

SWUST OJ(952)的更多相关文章

  1. [Swust OJ 404]--最小代价树(动态规划)

    题目链接:http://acm.swust.edu.cn/problem/code/745255/ Time limit(ms): 1000 Memory limit(kb): 65535   Des ...

  2. [Swust OJ 649]--NBA Finals(dp,后台略(hen)坑)

    题目链接:http://acm.swust.edu.cn/problem/649/ Time limit(ms): 1000 Memory limit(kb): 65535 Consider two ...

  3. SWUST OJ NBA Finals(0649)

    NBA Finals(0649) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 404 Accepted: 128   Descri ...

  4. [Swust OJ 1023]--Escape(带点其他状态的BFS)

    解题思路:http://acm.swust.edu.cn/problem/1023/ Time limit(ms): 5000 Memory limit(kb): 65535     Descript ...

  5. [Swust OJ 1125]--又见GCD(数论,素数表存贮因子)

    题目链接:http://acm.swust.edu.cn/problem/1125/ Time limit(ms): 1000 Memory limit(kb): 65535   Descriptio ...

  6. [Swust OJ 1126]--神奇的矩阵(BFS,预处理,打表)

    题目链接:http://acm.swust.edu.cn/problem/1126/ Time limit(ms): 1000 Memory limit(kb): 65535 上一周里,患有XX症的哈 ...

  7. [Swust OJ 1026]--Egg pain's hzf

      题目链接:http://acm.swust.edu.cn/problem/1026/     Time limit(ms): 3000 Memory limit(kb): 65535   hzf ...

  8. [Swust OJ 1139]--Coin-row problem

    题目链接:  http://acm.swust.edu.cn/contest/0226/problem/1139/ There is a row of n coins whose values are ...

  9. [Swust OJ 385]--自动写诗

    题目链接:http://acm.swust.edu.cn/problem/0385/ Time limit(ms): 5000 Memory limit(kb): 65535    Descripti ...

随机推荐

  1. 前缀判断|2013年蓝桥杯B组题解析第五题-fishers

    前缀判断 如下的代码判断 needle_start指向的串是否为haystack_start指向的串的前缀,如不是,则返回NULL. 比如:"abcd1234" 就包含了 &quo ...

  2. 如何查看sonarqube的版本

    Server Logs & System Info The System Info page is found at Administration > System. It gives ...

  3. (转)Understanding Memory in Deep Learning Systems: The Neuroscience, Psychology and Technology Perspectives

    Understanding Memory in Deep Learning Systems: The Neuroscience, Psychology and Technology Perspecti ...

  4. webpack用 babel将ES6转译ES5

    webpack webpack.config.js配置文件 module.exports = { entry: './es6.js', // 入口文件路径 output: { filename: &q ...

  5. Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project ppcloud-common: Compilation failure

    本文为博主原创,未经允许不得转载: [INFO] Finished at: 2018-09-19T20:26:05+08:00[INFO] ------------------------------ ...

  6. Mysql数据类型、约束、存储引擎

    一.数据类型 整数类型 默认有符号的 设置为无符号 1.create table t2(age tinyint unsigned); 2.建表后用alter修改 tinyint[(m)] [unsig ...

  7. 模块、包及常用模块(time/random/os/sys/shutil)

    一.模块 模块的本质就是一个.py 文件. 导入和调用模块: import module from module import xx from module.xx.xx import xx as re ...

  8. python实现八皇后问题

    import random def judge(state, nextX): #判断是否和之前的皇后状态有冲突 nextY = len(state) for i in range(nextY): if ...

  9. hdu 5724 Chess 博弈sg+状态压缩

    Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem De ...

  10. JAVA中使用浮点数类型计算时,计算精度的问题

    标题     在Java中实现浮点数的精确计算    AYellow(原作) 修改    关键字     Java 浮点数 精确计算   问题的提出:如果我们编译运行下面这个程序会看到什么?publi ...