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 ln (sizeof(struct Number)) typedef struct Number { int num; struct Number * next, * pre; }Num; int a = 0; Num *create() { Num *p_new1,*head,*p1; p1 = p_new1 = (Num *)malloc(ln); head = NULL; int m; scanf("%d",&m); while(m != 0) { if(a == 0) { head = p_new1; p1 = p_new1; head->pre = NULL; } else { p_new1->pre = p1; p1 -> next = p_new1; p1 = p1 -> next; } a ++; p1->num = m; scanf("%d",&m); p_new1 = (Num *)malloc(ln); } p1 -> next = NULL; return(head); } void print(Num * head) { Num * q; q = head; while(q -> num != 0) { printf("%d ",q -> num); q = q -> next; } } void printresort(Num * head) { Num * q; q = head; while(q->next) { q = q->next; } while(q) { printf("%d ",q->num); q = q->pre; } } int main() { Num *m; m = create(); print(m); printf("\n"); printresort(m); return 0; }
#include"stdio.h" #include"stdlib.h" #define ln (sizeof(struct Code)) FILE *fp; typedef char N; typedef struct Code { int col,raw;//第几行,第几列 N m;//储存的数值 struct Code * right,*left;//右指针和下指针 }Code,*codelink; typedef struct { codelink * r_head, * c_head;//行头,列头指针 }Crosslinking; int CreatMatrix(codelink * newo)//创建十字型链表 { N e; Code * p,* q; newo->r_head = NULL; newo->c_head = NULL; newo->r_head = (Code *)malloc(1001*ln); if(newo->r_head == NULL) printf("创建失败!"); newo->c_head = (Code *)malloc(1001*ln); if(newo->c_head == NULL) printf("创建失败!"); for(int i = 1;i <= 1000;i ++) { newo->r_head[i] = NULL; newo->c_head[i] = NULL; } q->right->col = q->down->raw = 1; int r,c; r = c = 1; for(int j = 1;j <= 1000*1000;j ++) { p = (Code *)malloc(ln); if(newo->r_head[j] == NULL) { newo->r_head[j] = p; } else { for(q = newo->r_head[r];q->right&&q->right->col <= 1000;q = q->right) p = q->right; col++; r ++; } if(newo->c_head[j] == NULL) { newo->c_head[j] = p; } else { for(q = newo->c_head[c];q->down&&q->down->raw <= 1000; q = q->down) p = q->down; raw++; c ++; } } return (newo); } //从文件输入俩方阵的数据 int insertA(codelink * newo) { codelink * newoA; newoA = newo; FILE * fpa; fpa = fopen("沙雕矩阵数据A.txt","r+");//此时有已经准备好的数据在“沙雕矩阵数据A.txt”文件里面(帅的人才能看见) Code * p; for(int i = 1;i <= 1000;i ++) { if(newo->r_head[1] == NULL) printf("该矩阵不存在"); else { p = newo->r_head[i]; while(p) { fread(p,ln,1,fp); p = p->right; } } } fclose(fpa); return newoA; } int insertB(codelink * newo) { codelink * newoB; newoA = newo; FILE * fpb; fpb = fopen("沙雕矩阵数据B.txt","r+");//此时有已经准备好的数据在“沙雕矩阵数据B.txt”文件里面(帅的人才能看见) Code * p; for(int i = 1;i <= 1000;i ++) { if(newo->r_head[1] == NULL) printf("该矩阵不存在"); else { p = newo->r_head[i]; while(p) { fread(p,ln,1,fp); p = p->right; } } } fclose(fp); return newoB; } // 矩阵相乘 int multiply(codelink * newoA,codelink * newoB) { codelink * A = NULL,* B = NULL,*newoD; N ee; for(int i = 1;i <= 1000;i ++) { A = newoA->r_head[i]; while(A != NULL) { B = newoB->r_head[A->c]; if(B==NULL) { continue; //B指向的节点是否存在 否 } else { if(B->c_read[A->r] == NULL) { continue;//B指向的节点是否存在 否 } else { for( ;B && B->right == newoB->c_read[A->r];B = B->right);//循环指向A对应的B中的节点 if(B == NULL) { continue;//B指向的节点是否存在 否 } else { ee = ee + A->e * B->e; //相乘运算 } } } } newoD -> e = ee; A = A->right; //用A将第一个矩阵的行进行遍历 } return newoD; } //结果输出 void show(codelink * newoD) { Code * p; for(int i = 1;i <= 1000;i ++) { if(newo->r_head[1] == NULL) printf("该矩阵不存在"); else { p = newo->r_head[i]; while(p) { printf("%d",p->m); p = p->right; } } } } int main() { CreatMatrix(); codelink * g,* h,* k; g = CreatMatrix(); h = multiply(insertA(g),insertB(g)); show(h); return 0; }
#include"stdio.h" #include"stdlib.h" #define ln (sizeof(struct Student)) typedef struct Student { int stunum; char name; int age; int sex;//0男 1女 int dnum; int bnum; struct Student * next; } Stu;//信息的设立 Stu * head; int a,b,c,d,e,f; int n; void scan() { printf("学号:"); scanf("%d",&a); printf("\n"); printf("姓名:"); scanf("%s",&b); printf("\n"); printf("年龄:"); scanf("%d",&c); printf("\n"); printf("性别:"); scanf("%d",&d); printf("\n"); printf("宿舍号:"); scanf("%d",&e); printf("\n"); printf("床号:"); scanf("%d",&f); printf("\n"); } Stu * creat()//录入信息 { printf("请输入您想要录入信息的学生数:"); scanf("%d",&n); if(n== 0) { head = NULL; return head; } Stu * p,*p_rail; for(int m = 1;m <= n;m ++) { p = (Stu *)malloc(ln); if(m==1) { head = p; p_rail = p; } else { p_rail->next = p; p_rail = p_rail->next; } scan(); p_rail->stunum = a; p_rail->name = b; p_rail->age = c; p_rail->sex = d; p_rail->dnum = e; p_rail->bnum = f; a = b = c = d = e = f =0; } p_rail->next = NULL; return(head); } void print(Stu * head)//输出信息 { Stu * q = head; if(q == NULL) { printf("信息为空"); exit(0); } printf("学生信息如下:\n"); while(q != NULL) { printf("%d %s %d %d %d %d",q->stunum,q->name,q->age,q->sex,q->dnum,q->bnum); q = q->next; } } //插入学生信息 void insert(Stu * head) { printf("请输入您想插入的学生信息:"); Stu * p_new = (Stu *)malloc(ln); scan(); p_new->stunum = a; p_new->name = b; p_new->age = c; p_new->sex = d; p_new->dnum = e; p_new->bnum = f; Stu *p; p = head; if(head == NULL) { head = p_new; p_new = NULL; } else { if(a < head->stunum) { p_new->next = head; head = p_new; } else { while(p->next && p->next->stunum < a) p = p->next; p_new->next = p->next; p->next = p_new; } } n = n + 1; } //???????为什么不能插到头上来 //查询某个学生信息 void serch (Stu * head) { Stu *m; printf("请输入您要查找的学生信息的学号:"); scanf("%d",&a); m = head; while(m -> stunum != a) m = m -> next; printf("%d %s %d %d %d %d",m->stunum,m->name,m->age,m->sex,m->dnum,m->bnum); } //删除某学生的信息 void del(Stu * head) { printf("请输入您要删除的信息的学生学号:"); int a; scanf("%d",&a); Stu * m,*n; n = m = head; if(head == NULL) { printf("信息不存在,无法删除"); return; } else { if(head->stunum == a) { head = m->next; free(m); } else { n = head; m = head->next; while(m->stunum != a && m!=NULL) { n = m; m = m->next; } if(m == NULL) { printf("无目标信息,无法删除!"); } else { n->next = m->next; free(m); } } } n = n - 1; }//删除第一个时乱码????? //用文件储存整个链表所有学生信息 void save(Stu * head) { FILE * fp; int i; if ((fp = fopen("stu.dot","w")) == NULL) { printf("不能打开文件"); return; } fwrite(head,ln,n,fp); fclose(fp); } int main() { int i; printf("**********************************\n"); printf("* 宿舍管理系统 *\n"); printf("* *\n"); printf("* 您可以进行的操作有: *\n"); printf("* *\n"); printf("* 1-录入学生的宿舍信息 *\n"); printf("* 2-查询某学生的宿舍信息 *\n"); printf("* 3-插入某学生的宿舍信息 *\n"); printf("* 4-删除某学生的宿舍信息 *\n"); printf("* *\n"); printf("* *\n"); printf("**********************************\n"); printf("请选择您想要的操作:"); scanf("%d",&i); Stu * j; if(i == 1) { j = creat(); print(j); save(j); printf("请选择您想要的操作:"); scanf("%d",&i); } if(i == 2) { serch(j); print(j); save(j); } if(i == 3) { insert(j); print(j); save(j); } if(i == 4) { del(j); print(j); save(j); } 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: