当前位置: 首页> 教育> 幼教 > 网页设计公司哪家效果好_b2b b2c c2c的含义分别是什么_学生个人网页制作html代码_好消息tvapp电视版

网页设计公司哪家效果好_b2b b2c c2c的含义分别是什么_学生个人网页制作html代码_好消息tvapp电视版

时间:2025/7/9 17:06:14来源:https://blog.csdn.net/2302_80782671/article/details/142470023 浏览次数:0次
网页设计公司哪家效果好_b2b b2c c2c的含义分别是什么_学生个人网页制作html代码_好消息tvapp电视版

题目描述

根据输入数据创建链表,并输出指定位置的数据

如果输入位置不存在,则输出“位置有误”

注意:要求用尾插法,头插法创建之后求的结果是肯定是错误的

输入

第一行输入一个整数n
第二行输入n个整数
第三行输入一个整数p

输出

第p个数据的值

#include "stdio.h"
#include "stdlib.h"struct node{int data;struct node *next;
};void destroylink(struct node *h);   
struct node * createlink(int n);
struct node * findbypos(struct node *h,int pos);main()
{struct node *p,*head=NULL;int n,d;scanf("%d",&n);head = createlink(n);scanf("%d",&d);p = findbypos(head,d);//输出结果if (p == NULL) {printf("位置有误");} else {printf("%d", p->data);}destroylink(head);  
}struct node * createlink(int n) {struct node *head = NULL;struct node *tail = NULL;int data;for (int i = 0; i < n; i++) {scanf("%d", &data);struct node *newNode = (struct node *)malloc(sizeof(struct node));newNode->data = data;newNode->next = NULL;if (head == NULL) {head = newNode;tail = newNode;} else {tail->next = newNode;tail = newNode;}}return head;
}struct node * findbypos(struct node *h,int pos) {struct node *current = h;int count = 1;while (current!= NULL) {if (count == pos) {return current;}current = current->next;count++;}return NULL;
}void destroylink(struct node *h)
{struct node *q;while(h!=NULL){q=h;h=h->next;free(q);}
}

关键字:网页设计公司哪家效果好_b2b b2c c2c的含义分别是什么_学生个人网页制作html代码_好消息tvapp电视版

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: