单链表上查找算法的实现

 #include <stdio.h>
#include <stdlib.h> typedef struct LinkNode //单链表节点结构的定义
{
int data;
struct LinkNode *next;
}LinkNode; void InitLinkList(LinkNode * &L)
{
/*单链表的初始化*/
L = (LinkNode*)malloc(sizeof(LinkNode));
L->next = NULL;
} void CreateLinkList(LinkNode *&L, int n,int *num)
{
/*采用尾插法创建单链表*/
LinkNode* r = L;
for (int i = ; i < n; ++i)
{
LinkNode * p =(LinkNode*)malloc(sizeof(LinkNode));
p->data = num[i];
p->next = r->next;
r->next = p;
r = p;
}
} int main(int argc, char const *argv[])
{
/*int n = 5;
int num[]={1,2,3,4,5};*/
int n, p;
int *num; scanf("%d",&n);
num =(int*)malloc(n*sizeof(int)); for (int i = ; i < n; ++i)
{
scanf("%d",&num[i]);
} scanf("%d",&p); LinkNode *L;
InitLinkList(L);
CreateLinkList(L,n,num); if (p>&&p<n)
{
printf("ok");
}
else
{
printf("error");
} return ;
}

注:实际上对于这道题,代码中好多部分都是多余的,亲测下面的代码也能AC

 #include<stdio.h>
#include <stdlib.h>
int main()
{
int n,p;
int *num;
scanf("%d",&n);
num =(int*)malloc(n*sizeof(int));
for (int i = ; i < n; ++i)
{
scanf("%d",&num[i]);
}
scanf("%d",&p);
if (p<n&&n>)
{
printf("ok");
}
else
{
printf("error");
}
return ;
}

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

  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. P3261 [JLOI2015]城池攻占

    思路 左偏树维护每个骑士的战斗力和加入的深度(因为只能向上跳) 注意做乘法的时候加法tag会受到影响 代码 #include <cstdio> #include <algorithm ...

  2. The issus in Age Progression/Regression by Conditional Adversarial Autoencoder (CAAE)

    The issus in Age Progression/Regression by Conditional Adversarial Autoencoder (CAAE) Today I tried ...

  3. Tag Helpers in forms in ASP.NET Core

    Tag Helpers in ASP.NET Core Tag Helpers in forms in ASP.NET Core HTML Form element ASP.NET Core buil ...

  4. VirtuablBox 出错: VERR_SUPLIB_OWNER_NOT_ROOT 解决方法

    刚刚把 VirtualBox 升级, 从 3.2 到 4.0.4 后,虚拟机上的系统无法运行, 提示: VERR_SUPLIB_OWNER_NOT_ROOT 查了一下,发现是因为 /opt 的 own ...

  5. ZOJ 3987 Numbers(Java枚举)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3987 题意:给出一个数n,现在要将它分为m个数,这m个数相加起来必须等于n ...

  6. windows下远程连接Mysql

    使用“Ctrl + R”组合键快速打开cmd窗口,并输入“cmd”命令,打开cmd窗口. 使用“mysql -uroot -proot”命令可以连接到本地的mysql服务. 使用“use mysql” ...

  7. JS实现ul,li排序效果

    <!DOCTYPE html> <html> <head> <title>js列表排序</title> <meta charset=& ...

  8. 《spring boot 实战》读书笔记

    前言:虽然已经用spring boot开发过一套系统,但是之前都是拿来主义,没有系统的,全面的了解过这套框架.现在通过学习<spring boot实战>这本书,希望温故知新.顺便实现自己的 ...

  9. memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory

    1.在http://libevent.org/   下载libevent-2.0.22-stable.tar.gz 2.tar -zxvf libevent-2.0.22-stable.tar.gz ...

  10. IIS7 配置Http重定向到Https

    1.注意首先要安装url重定向模块 微软官方地址:https://www.microsoft.com/zh-CN/download/details.aspx?id=7435 百度网盘地址:链接: ht ...