c语言链表及其相关操作代码
链表动态创建#include#include#includestruct Student{char num[10]; //字符串学号char name[10]; //字符串姓名double score; //双精度实型成绩struct Student *next; //用与构建链表指向下一结点};struct Student *creatlinklist()//当成绩项目输入0时,创建链表结束{struct Student *head;struct Student *p1,*p2;int n;n=0;head=NULL;p1=(struct Student *)malloc(sizeof(struct Student));printf("请输入学号姓名和成绩\n");scanf("%s%s%lf",p1->num,p1->name,&p1->score);while(p1->score!=0){if(n==0){head=p1;p2=p1;n++;}else{p2->next=p1;p2=p1;n++;}p1=(struct Student *)malloc(sizeof(struct Student));printf("请输入学号姓名和成绩\n");scanf("%s%s%lf",p1->num,p1->name,&p1->score);}if(head!=NULL)p2->next=NULL;return head;}voidprint_linklist(struct Student *head){struct Student *pi;if(head==NULL){printf("空链表!\n");}else{printf("学号\t姓名\t成绩\n");for(pi=head;pi!=NULL;pi=pi->next){printf("%s\t%s\t%lf\n",pi->num,pi->name,pi->score);}}}int main(){struct Student *head;head=creatlinklist();print_linklist(head);return 0;}/链表查找#include#include#includestruct Student{char num[10]; //字符串学号char name[10]; //字符串姓名double score; //双精度实型成绩struct Student *next; //用与构建链表指向下一结点};struct Student *creatlinklist(){struct Student *head;struct Student *p1,*p2;int n;n=0;head=NULL;p1=(struct Student *)malloc(sizeof(struct Student));printf("请输入学号姓名和成绩\n");scanf("%s%s%lf",p1->num,p1->name,&p1->score);while(p1->score!=0){if(n==0){head=p1;p2=p1;n++;}else{p2->next=p1;p2=p1;n++;}p1=(struct Student *)malloc(sizeof(struct Student));printf("请输入学号姓名和成绩\n");scanf("%s%s%lf",p1->num,p1->name,&p1->score);}if(head!=NULL)p2->next=NULL;return head;}voidprintlinklist(struct Student *head){struct Student *pi;if(head==NULL){printf("空链表!\n");}else{printf("学号\t姓名\t成绩\n");for(pi=head;pi!=NULL;pi=pi->next){printf("%s\t%s\t%lf\n",pi->num,pi->name,pi->score);}}}struct Student * find_linklist_by_name(struct Student *head,char name[]){struct Stud