We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#include<stdio.h> #include<stdlib.h> #define LEN sizeof(struct re) struct re { char ch; struct re * next; }; //创建链表 struct re * creat(int n) { int i; struct re * head, * pp,* p; head=NULL; pp=p=(struct re*) malloc(LEN); if(p!=NULL) { scanf("%d",&p->ch); head=p; pp=p; } for(i=1;i<n;i++) { p=(struct re*)malloc(LEN); if(p!=NULL) { scanf("%d",&p->ch); pp->next=p; pp=p; } } p->next=NULL; return head; } struct re *reverse(struct re *head) { struct re *p=head,*q; head=NULL; while(p) { q=p; p=p->next; q->next=head; head=q; } return head; } void print(struct re *head) { struct re *p; p=head; if(head!=NULL) { do { printf("%d",p->ch); p=p->next; }while(p!=NULL); } } int main() { int n; printf("请输入要逆向的数字个数:\t"); scanf("%d",&n); struct re*head; head=creat(n); head=reverse(head); print(head); return 0; }
#include<stdio.h> #include<stdlib.h> #include<string.h> typedef struct room{ int id; char name[100]; char sex[100]; int age; int x; //宿舍号 int y; //床位号 struct room*next; }room; room* creat(int n) { int k=0; room*p,*head; head=NULL; while(k<n) { p=(room*)malloc(sizeof(room)); printf("\n请输入学生学号\n"); scanf("%d",&p->id); printf("\n请输入学生姓名\n"); scanf("%s",p->name); printf("\n请输入学生性别\n"); scanf("%s",p->sex); printf("\n请输入学生年龄\n"); scanf("%d",&p->age); printf("\n请输入学生的宿舍号\n"); scanf("%d",&p->x); printf("\n请输入学生的床位号\n"); scanf("%d",&p->y); p->next=head; head=p; k++; } return head; } //输出 void pt(room*head) { room*p; p=head; if(p==NULL) { printf("空"); } else while(p!=NULL) { printf("\n学号:%d\t姓名:%s\t性别:%s年龄:%d\t宿舍:%d\t床位:%d\n",p->id,p->name,p->sex,p->age,p->x,p->y); p=p->next; } } //查询 room* scearch(room*head) { room *p; p=head; char namee[100]; printf("\n请输入要查找的名字:\n"); scanf("%s",namee); while(p) { if(strcmp(p->name,namee)==0) { printf("\n学号:%d\t姓名:%s\t性别:%s年龄:%d\t宿舍:%d\t床位:%d\n",p->id,p->name,p->sex,p->age,p->x,p->y); } if(strcmp(p->name,namee)!=0&&p->next==NULL) { printf("\n未找到该同学\n"); } p=p->next; } return p; } //插入 room* find(room* head) { room*p,*q,*q1; p=head; char name2[100]; printf("\n请输入要插入的位置的前一位姓名:\n"); scanf("%s",name2); while(p&&strcmp(p->name,name2)!=0) { p=p->next; } char name1[100],sex1[100]; int id1,age1,x1,y1; printf("\n请输入添加同学的学号,姓名,性别,年龄\n"); scanf("%d%s%s%d%d%d",&id1, name1, sex1, &age1, &x1, &y1); q=head; q1=p; q=(room*)malloc(sizeof(room)); q->id=id1; strcpy(q->name,name1); strcpy(q->sex,sex1); q->age=age1; q->x=x1; q->y=y1; if(q1==head) { q->next=head; head=q; } else { q->next=q1->next; q1->next=q; } return head; } room* dete(room *head) { room *p,*pp; if(head==NULL) { printf("链表为空!"); } char namee[100]; printf("\n请输入要删除的名字:\n"); scanf("%s",namee); p=head; pp=NULL; while(p&&strcmp(p->name,namee)!=0) { pp=p; p=p->next; } if(p==NULL) { printf("\n没有找到要删除的同学\n"); } if(!pp&&strcmp(p->name,namee)==0) head=NULL; else pp->next=p->next; do{ p=p->next; }while(p!=NULL); return head; } void enter(room *head,int n) { FILE *fp; fwrite(head,sizeof(room),n,fp); printf("成功录入!"); } int main() { room* list; int n,a; printf("\n请输入所创建的容量\n"); scanf("%d",&n); printf("\n请输入各同学信息:\n"); list=creat(n); int input; while(1) { printf("\n请输入要执行操作序号:\n1、输出\n2、查找某同学的信息\n3、删除某同学信息\n4、插入\n"); scanf("%d",&input); switch(input) { case 1:pt(list);break; case 2:scearch(list);break; case 3:list = dete(list);break; case 4:list = find(list);break; } printf("完成时请输入 0 ,继续操作请输入 1 \n"); scanf("%d",&a); if(a==0) break; } enter (list,n); return 0; }
#include<stdio.h> #include<stdlib.h> #define N 1000 struct stu { int num; struct stu *next; }; struct stu *creat1() { //创建第一个矩阵 int i=0,j=1; struct stu *head,*pp,*p; pp=p=(struct stu*)malloc(sizeof(struct stu)); scanf("%d",&p->num); head=p; pp=p; for(; i<N; i++) { for(; j<N; j++) { p=(struct stu*)malloc(sizeof(struct stu)); scanf("%d",&p->num); pp->next=p; pp=p; } pp->next=NULL; j=0; } return head; } struct stu *creat2() { //创建第二个矩阵 int i=0,j=1; struct stu *head,*pp,*p; pp=p=(struct stu*)malloc(sizeof(struct stu)); scanf("%d",&p->num); head=p; pp=p; for(; i<N; i++) { for(; j<N; j++) { p=(struct stu*)malloc(sizeof(struct stu)); scanf("%d",&p->num); pp->next=p; pp=p; } pp->next=NULL; j=0; } return head; } void mul(struct stu *q1,struct stu *q2) { struct stu *p1,*p2; p1=q1; p2=q2; int i,j,x,y,a=0; long int sum=0; for (i=0; i<N; i++) { for (j=0; j<N; j++) { p1=q1; for (x=0; x<i*N; x++) { p1=p1->next; } p2=q2; for (x=0; x<j; x++) { p2=p2->next; } sum=0; for (y=0; y<N; y++) { sum+=p1->num*p2->num; p1=p1->next; for (x=0; p2!=NULL&&x<N; x++) { p2=p2->next; } } if(a==0) { a=1; printf("\n结果是:\n"); } printf("%.ld\t",sum); } printf("\n"); } } int main() { struct stu *q1,*q2,*list; printf("请输入的第一个矩阵:\n"); q1=creat1(); printf("请输入的第二个矩阵:\n"); q2=creat2(); mul(q1,q2); return 0; }
The text was updated successfully, but these errors were encountered:
点评:
链表倒序
宿舍管理系统
修改!
Sorry, something went wrong.
修改: 链表倒序 已添加提示信息 宿舍管理系统 删除操作已修改 文件已添加(可能还存在错误,希望学长指正)
修改:
No branches or pull requests
链表倒序
宿舍管理系统
矩阵相乘
The text was updated successfully, but these errors were encountered: