Open Furaming opened 4 years ago
比较咸鱼 完成老师的大作业程序,发现自己的软件跟同学的不太一样,目前在想函数调用方法和文件不太一样菜鸡要如何适应。加油朋友!(应该没啥人看我写这东西?爬走) 学链表,那个删除的链表代码我咋看咋对,不懂错哪里了,有木有大佬带我飞一下???
#include <stdio.h> #include <stdlib.h> #define M 10 struct student { int number; char n[20]; char sex; int age; struct student *next; }; struct student lian[M]= { {1,"yihao",'F',18,&lian[1]}, {2,"erhao",'F',19,&lian[2]}, {3,"sanhao",'M',17,&lian[3]}, {4,"sihao",'F',19,&lian[4]}, {5,"wuhao",'M',19,&lian[5]}, {6,"liuhao",'M',20,&lian[6]}, {7,"qihao",'F',19,&lian[7]}, {8,"bahao",'M',17,&lian[8]}, {9,"jiuhao",'F',19,&lian[9]}, {10,"shihao",'M',18,NULL}, }; struct student *del(struct student *head) { struct student *p1,*p2=NULL; int age; scanf("%d",&age); if(head==NULL) printf("list is null"); else { p1=head; while(p1->age!=age) { p2=p1; p1=p1->next; } if(p1->age==age) { if(p1==head) { head=p1->next; free(p1); } else { p2->next=p1->next; p1->next=NULL; free(p1); } } } return head; } void print(struct student *head) { struct student *p; p=head; while(p!=NULL) { printf("第%d号姓名为%s,性别:%c,年龄:%d\n",p->number,p->n,p->sex,p->age); p=p->next; } } int main() { int n; scanf("%d",&n); del(lian); print(lian); return 0; }
学会链表!!接就完事了? 299 学写贪吃蛇不晓得有没有希望,没有#include<window.h>,看不起我?
#include<window.h>
本周15周
下周16周