当前位置:网站首页>DHU programming exercise
DHU programming exercise
2022-06-30 02:09:00 【qq_ forty-three million four hundred and three thousand six hun】
1 Find sequence elements ( Linked list )
#include<iostream>
using namespace std;
/* to define a linklist node*/
struct node {
int val;
struct node *next;
};
/*create a list based on data input*/
node *createList() {
node *head = NULL, *p, *tail = NULL;
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
int num;
cin >> num;
p = (node*)malloc(sizeof(node));//generate a new node
if (head == NULL)
head = p;
else
tail->next = p;
p->val = num;
p->next = NULL;
tail = p;
}
return head;
}
/*traverse the linklist and find the target's location*/
int Locate(node *head, int num)
{
node *p;
p = head;
int location = 1;
while (p)
{
if (p->val == num)
break;
p = p->next;
location++;
}
if (p == NULL)
return 0;
else
return location;
}
int main() {
struct node *head;
head = createList();
int num;
while (cin>>num)
{
int loc = Locate(head, num);
if (loc != 0)
cout << loc << endl;
else
cout << "no" << endl;
}
return 0;
}
边栏推荐
- AI landing manufacturing: intelligent robots should have these four abilities
- Let‘sPlayCurling
- 208. implement trie (prefix tree) - attach detailed notes
- 003_ color
- 假離婚變成真離婚,財產怎麼辦
- Leetcode 46 Full arrangement (February 15, 2022)
- What problems can cloud storage architecture solve for Devops?
- Widget uses setimageviewbitmap method to set bug analysis
- 26.算法常用面试题
- 网上炒股安全么?炒股需要开户吗?
猜你喜欢

Illustration Google V8 19: asynchronous programming (II): how does V8 implement async/await?

After the blueprint node of ue5 is copied to UE4, all connections and attribute values are lost

云存储架构能解决 DevOps 的什么问题?

002_ container

【银河麒麟V10】【桌面】火狐浏览器设置主页不生效

Want to change careers, but don't know what you want to do?
![[graph neural network] summary of graph classification study [3]: evaluation of graph classification methods and future research directions](/img/b1/2afa73a14b2f41b7a65c4c2d261e6a.png)
[graph neural network] summary of graph classification study [3]: evaluation of graph classification methods and future research directions

DTW学习(dynamic time warping)——思想、代码实现

Openlayers 3 built in interaction

Matlab 2012a 绘制带箭头的线段
随机推荐
DDoS threat situation gets worse
Record an oom exception in production
AI落地制造业:智能机器人应具备这4种能力
Comprendre le principe AQS (organigramme et schéma de file d'attente synchrone)
網上炒股安全麼?炒股需要開戶嗎?
A keepalived high availability accident made me learn it again!
Is online stock trading safe? Do you need to open an account for stock trading?
Internet Crime Complaint Center reports an increase in DDoS Attacks
Gesture digital enlightenment learning machine
DMX的配置
Learning C language from scratch day 026
CTF introductory learning (WEB direction)
魔百盒CM201-2-CH-Hi3798MV300-300H-EMMC和NAND_红外蓝牙语音_通刷固件包
(4) Blender source code analysis flash window display process
9 — 正则校验集合
【自然语言处理】【多模态】OFA:通过简单的sequence-to-sequence学习框架统一架构、任务和模态
DDoS threat situation gets worse
9 - regular check set
Conversion between opencv and image (valid for pro test)
Upload, use of Avatar