当前位置:网站首页>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;
}
边栏推荐
- Who can use redis expired monitoring to close orders and get out of here!
- ROS bridge notes (01) - APT installation, source code compilation and installation, installation dependency, and operation display
- Fake divorce turns into real divorce. What about property
- CTF入门学习(Web方向)
- Where can I find a pre training model for pytoch model training?
- Derivation of univariate polynomial in C language
- C language number prime
- Write this number in C
- Upload, use of Avatar
- 005_ button
猜你喜欢

【自然语言处理】【多模态】OFA:通过简单的sequence-to-sequence学习框架统一架构、任务和模态

DMX的配置

018_ rate

The (3n+1) conjecture that C language kills people without paying for their lives

Realization of a springboard machine

Jenkins continuous integration environment construction VII (Jenkins parametric construction)

DMX configuration
![[MySQL 06] backup and restore MySQL database in Linux + docker container environment](/img/4e/8662d15ff84b2436d02948019540d3.png)
[MySQL 06] backup and restore MySQL database in Linux + docker container environment

一种跳板机的实现思路

Share the source code of the website of graduation student record
随机推荐
[graph neural network] summary of graph classification study [3]: evaluation of graph classification methods and future research directions
The odoo15 page jumps directly to the editing status
Internet Crime Complaint Center reports an increase in DDoS Attacks
7 — filter
Yyds dry inventory consistent and smooth zoom type and spacing
js Array. Five convenient applications of from()
AI落地制造业:智能机器人应具备这4种能力
If mybaits cannot query the data, it can query how to change it in the database
DDoS attacks - are we really at war?
Gesture digital enlightenment learning machine
The (3n+1) conjecture that C language kills people without paying for their lives
一次 Keepalived 高可用的事故,让我重学了一遍它!
DDoS "fire drill" service urges companies to prepare
[pytorch actual combat] generate confrontation network Gan: generate cartoon character avatars
Restore a 35k-55k Tencent Android Senior Engineer Interview
Record an oom exception in production
[mrctf2020]ezpop-1 | PHP serialization
Derivation of univariate polynomial in C language
魔百盒CM201-2-CH-Hi3798MV300-300H-EMMC和NAND_红外蓝牙语音_通刷固件包
Share the source code of the website of graduation student record