|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 Ryan_Li 于 2021-3-28 15:21 编辑
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct student{
- char name[8];
- int num;
- }STUD;
- typedef struct node{
- STUD stu;
- struct node *next;
- }LNode;
- STUD *CreatStudent(){
- printf("请输入学生学号、姓名:");
- STUD *stu;
- scanf("%d %s",stu->num,stu->name);
- return stu;
- }
- LNode *InitList(){
- LNode *head = NULL;
- head =(LNode*)malloc(sizeof(LNode));
- head->next=NULL;
- return head;
- }
- LNode *CreatList(){
- LNode *head,*p;
- int num;
- char name[8];
- head =InitList(); //头结点生成
- head->next=NULL;
- printf("开始录入数据:\n");
- scanf("%d %s",&num,name); //放外面是方便和下面形成循环
- while(num!=-1){
- p=(LNode*)malloc(sizeof(LNode));
- p->stu.num=num;
- strcpy(p->stu.name,name);
- p->next=head->next;
- head->next=p;
- scanf("%d %s",&num,name);
- }
- printf("录入结束!\n");
- return head;
- }
- LNode *DisplayList(LNode *l){
- LNode *p=l->next;
- while(p!=NULL){
- printf("%d %s\n",p->stu.num,p->stu.name);
- p=p->next;
- }
- return p;
- }
- LNode *LocateList(STUD *stu,LNode *l){
- LNode *a=l->next;
- while(a->stu.num!=stu->num){
- a=a->next;
- }
- return a;
- }
- int main(){
- LNode* l=CreatList();
- STUD stu = {"ada",123};
- DisplayList(l);
- LNode *p = LocateList(stu,l);
- return 0;
- }
复制代码
locate函数哪里错了 |
|