17070047 / 17070047/CodeStructureCourse

1707004709王晶

Offen
#79 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C++
Sterne
16
Forks
2
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

```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)

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

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().

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
c
Bereich
cli
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
20/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.