有一链式结构定义如下 :struct stuchar name20;int no;struct stu next;;创建一个函数create实现无头结点的链表有m个结点函数的返回值为链表的头指针。函数接口定义:在这里描述函数接口。例如:struct stu create在这里解释接口参数。在函数中输入m及m行数据完成链表的创建。裁判测试程序样例:在这里给出函数被调用进行测试的例子。例如:#inc
struct stu * create() { int m; scanf("%d", &m); //输入结点个数 struct stu *head = NULL, *tail = NULL; for (int i = 0; i < m; i++) { struct stu *p = (struct stu *)malloc(sizeof(struct stu)); scanf("%s %d", p->name, &(p->no)); //输入结点信息 p->next = NULL; if (head == NULL) //如果当前结点是第一个结点 { head = p; tail = p; } else //如果当前结点不是第一个结点 { tail->next = p; //将当前结点挂在链表尾部 tail = p; //更新链表尾指针 } } return head; //返回链表头指针
原文地址: https://www.cveoy.top/t/topic/cFGu 著作权归作者所有。请勿转载和采集!