17070047 / 17070047/CodeStructureCourse

1707004709王晶

未关闭
#79 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
C++
星标
16
派生
2
PR 合并指标
30 天内没有已合并 PR

描述

```c#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#define m 2000
typedef struct{
int key;
char name[20];
int j;
int k;
}recordtype;
typedef struct{
recordtype r[m+1];
int length;
}table;
void init(table *tab)
{
tab->length=0;
}
table *creat(int n)
{
table *tab;
tab=(table*)malloc(sizeof(table));
int i, j, k,a,b;
char name[20];
for(i=1;i<=n;i++)
{
printf("请输入卡号:");
scanf("%d",&k);
tab->r[i].key=k;
printf("请输入名字:");
scanf("%s",&name);
getchar();
strcpy(tab->r[i].name,name);
printf("请输入系别:");
scanf("%d",&a);
tab->r[i].j=a;
printf("请输入班级:");
scanf("%d",&b);
tab->r[i].k=b;
}
return tab;
}
void quicksort(table *tab,int left,int right)
{
int i,j;
if(leftr[0].key=tab->r[i].key;
strcpy(tab->r[0].name,tab->r[i].name);
tab->r[0].j=tab->r[i].j;
tab->r[0].k=tab->r[i].k;
do
{
while(tab->r[j].key>tab->r[0].key&&ir[i].key=tab->r[j].key;
strcpy(tab->r[i].name,tab->r[j].name);
tab->r[i].j=tab->r[j].j;
tab->r[i].k=tab->r[j].k;
i++;
}
while(tab->r[i].keyr[0].key&&ir[j].key=tab->r[i].key;
strcpy(tab->r[j].name,tab->r[i].name);
tab->r[j].j=tab->r[i].j;
tab->r[j].k=tab->r[i].k;
j--;
}
}while(i!=j);
tab->r[i].key=tab->r[0].key;
strcpy(tab->r[i].name,tab->r[0].name);
tab->r[i].j=tab->r[0].j;
tab->r[i].k=tab->r[0].k;
quicksort(tab,left,i-1);
quicksort(tab,i+1,right);
}

}
void search(table *tab,int i,int n)
{
int a;
for(a=1;a<=n;a++)
{
if(tab->r[a].j==i)
printf("卡号:%d 姓名:%s 系别:%d 班级:%d",tab->r[a].key,&tab->r[a].name,tab->r[a].j,tab->r[a].k);
}

}
void display(table *tab,int n)
{
int i;
for(i=1;i<=n;i++)
{
printf("卡号:%d 姓名:%s 系别:%d 班级:%d\n",tab->r[i].key,tab->r[i].name,tab->r[i].j,tab->r[i].k);
}
}
int main()
{
int i,j,k,n;
table *tab;
printf("请输入学生个数:");
scanf("%d",&n);
tab=(table*)malloc(sizeof(table));
init(tab);
tab=creat(n);
printf("按卡号排序的结果是:");
quicksort(tab,1,n);
display(tab,n);
printf("请输入要查找的系别");
scanf("%d",&i);
printf("请输出系别%d借书的学生信息:",i);
search(tab,i,n);
//display(tab,n);
return 0;
}
```
![ijz4o y6 o k31j c 0w 8](https://user-images.githubusercontent.com/39999166/49654225-365bc600-fa72-11e8-92e5-31bb89f343d6.png)

贡献指南

这个仓库没有索引到贡献指南

调研方向

The issue contains a C program for managing student records with sorting and search functions. The problem is not described; the user posted code and an image link. To start, examine the code in the issue body for logical errors, memory leaks, or incorrect sorting. Run the program to see if it crashes or produces wrong output. The image might show an error, but it's not accessible. Focus on the quicksort implementation and memory allocation in creat().

由索引模型根据 Issue 内容生成。

评估

技术栈
c
领域
cli
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
20/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。