SWUST OJ (943)
顺序表插入操作的实现
#include<stdio.h>
#include <stdlib.h> void InitList(int *&l, int n)
{
l = (int*)malloc(n*sizeof(int));
} void CreateList(int *&L,int n,int *array)
{
int *c = L;
while(n--)
{
*c++ = *array++;
}
} void InsertList(int *&l,int n,int item, int data)
{
int flag = n;
for(int i=;i<n;i++)
{
if (l[i]==item)
{
flag = i;
}
} /*
c库函数 void *realloc(void *ptr, size_t size) 尝试重新调整之前调用 malloc 或 calloc 所分配的 ptr 所指向的内存块的大小。
该函数返回一个指针指向重新分配大小的内存;
ptr -- 指针指向一个要重新分配内存的内存块,该内存块之前是通过调用 malloc、calloc 或 realloc 进行分配内存的。如果为空指针,
则会分配一个新的内存块,且函数返回一个指向它的指针。
size -- 内存块的新的大小,以字节为单位。如果大小为 0,且 ptr 指向一个已存在的内存块,则 ptr 所指向的内存块会被释放,并返回一个空指针。
*/
int *newbase =(int*)realloc(l,(n+)*sizeof(int));
l = newbase; if (flag!=n)
{
int *q = &(l[flag]);
for(int *p = &(l[n-]); p>=q; p--)
{
*(p+) = *p;
}
*q = data;
}
else
{
int *p = &(l[n]);
*p = data;
}
} void DisList(int *b,int n)
{
while(n--)
{
printf("%d ",*b++);
}
} int main(int argc, char const *argv[])
{
/*int n = 10;
int array[] = {10,20,30,40,50,60,70,80,90,100};
int item = 50;
int data = 55;*/ int n,item,data;
int *array;
scanf("%d",&n);
array = (int*)malloc(n*sizeof(int));
for (int i = ; i < n; ++i)
{
scanf("%d",&array[i]);
} scanf("%d",&item);
scanf("%d",&data); int *l;
InitList(l,n);
CreateList(l,n,array);
InsertList(l,n,item,data);
DisList(l,n+);
return ;
}
SWUST OJ (943)的更多相关文章
- [Swust OJ 404]--最小代价树(动态规划)
题目链接:http://acm.swust.edu.cn/problem/code/745255/ Time limit(ms): 1000 Memory limit(kb): 65535 Des ...
- [Swust OJ 649]--NBA Finals(dp,后台略(hen)坑)
题目链接:http://acm.swust.edu.cn/problem/649/ Time limit(ms): 1000 Memory limit(kb): 65535 Consider two ...
- SWUST OJ NBA Finals(0649)
NBA Finals(0649) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 404 Accepted: 128 Descri ...
- [Swust OJ 1023]--Escape(带点其他状态的BFS)
解题思路:http://acm.swust.edu.cn/problem/1023/ Time limit(ms): 5000 Memory limit(kb): 65535 Descript ...
- [Swust OJ 1125]--又见GCD(数论,素数表存贮因子)
题目链接:http://acm.swust.edu.cn/problem/1125/ Time limit(ms): 1000 Memory limit(kb): 65535 Descriptio ...
- [Swust OJ 1126]--神奇的矩阵(BFS,预处理,打表)
题目链接:http://acm.swust.edu.cn/problem/1126/ Time limit(ms): 1000 Memory limit(kb): 65535 上一周里,患有XX症的哈 ...
- [Swust OJ 1026]--Egg pain's hzf
题目链接:http://acm.swust.edu.cn/problem/1026/ Time limit(ms): 3000 Memory limit(kb): 65535 hzf ...
- [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 ...
- [Swust OJ 385]--自动写诗
题目链接:http://acm.swust.edu.cn/problem/0385/ Time limit(ms): 5000 Memory limit(kb): 65535 Descripti ...
随机推荐
- 【做题】arc070_f-HonestOrUnkind——交互+巧妙思维
做的第一道交互题-- 首先,有解的一个必要条件是\(a>b\).否则,即当\(a<=b\)时,可以有\(a\)个unkind的人假装自己就是那\(a\)个honest的人.(彼此之间都说是 ...
- 【注册码】Matlab7.0(R14)注册码
Matlab 7 (R14) 注册码1:14-13299-56369-16360-32789-51027-35530-39910-50517-56079-43171-43696-14148-64597 ...
- LuoguP2257 YY的GCD
题目描述 神犇YY虐完数论后给傻×kAc出了一题 给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的(x, y)有多少对 kAc这种傻×必然不会了,于 ...
- facebook api之Access and Authentication
Access and Authentication There are three access levels to the Marketing APIs. You can upgrade acces ...
- 3、Python迭代器、列表解析及生成器(0530)
1.动态语言 sys.getrefcount() //查看对象的引用计数 增加对象的引用计数场景 对象创建时:以赋值的方式,创建变量名的同时就会创建变量 将对象添加进容器时:类似list.app ...
- QT移植无法启动 This application failed to start because it could not find or load the QT platform
QT配置好在自己机器上可以运行,但在别人机器上一直弹出 "This application failed to start because it could not find or load ...
- Create and format Word documents using R software and Reporters package
http://www.sthda.com/english/wiki/create-and-format-word-documents-using-r-software-and-reporters-pa ...
- _pvp_killed_loot
该表控制玩家被击杀时掉落物品,包括角色身上装备,背包物品,银行物品 comment 备注 entry 掉落的物品ID lootCount 掉落的物品数量 chance 掉落的几率,例如50,则50%几 ...
- javaSE习题 第三章 运算符、表达式和语句
问答: 1.下列System.out.printf的结果是什么? int a=100,x,y; x=++a; y=a--; System.out.printf("%d,%d,%d" ...
- [转][osg][QT]osg与QT界面结合的简单例子
//QT += core gui opengl //LIBS += -losgViewer -losgDB -losgUtil -losg -lOpenThreads -losgGA -losgQt ...