17070047 / 17070047/CodeStructureCourse
1707004709王晶
- Langage dominant
- C++
- Étoiles
- 16
- Forks
- 2
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
```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;
}
```

Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
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().
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- c
- Domaine
- cli
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 20/100