17070047 / 17070047/CodeStructureCourse
段玉兰
- Vorherrschende Sprache
- C++
- Sterne
- 16
- Forks
- 2
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
```c
#include"stdio.h"
#include"string.h"
#define maxsize 1000
typedef struct{
char name[30];
char classnumber[30];
char card[30];
char department[30];
}library;
typedef struct{
library a[maxsize];
int len;
}seqlist;
/*创建*/
seqlist create()
{
seqlist t;
int i,n;
t.len=0;
printf("请输入要录入的信息个数:");
scanf("%d",&n);
t.len=n;
printf("请依次输入姓名、系别、班号、卡号:\n");
for(i=1;i<=n;i++)
{
scanf("%s",&t.a[i].name);
scanf("%s",&t.a[i].department);
scanf("%s",&t.a[i].classnumber);
scanf("%s",&t.a[i].card);
}
return t;
}
/*检索*/
void seqsearch(seqlist p)
{
int k,i;
k=p.len;
char key[8];
printf("请输入要检索的系别:\n");
scanf("%s",&key);
printf("----------------------------");
for(i=1;i<=k;i++)
{
if(strcmp(p.a[i].department,key)==0)
{
printf("\n%s ",p.a[i].name);
printf("%s ",p.a[i].department);
printf("班号:%s ",p.a[i].classnumber);
printf("卡号:%s \n",p.a[i].card);
}
}
}
/*快排*/
seqlist *quicksort(seqlist *seq,int left,int right)
{
int i,j,l;
if(lefta[0]=seq->a[i];
do{
while(strcmp(seq->a[j].card,seq->a[0].card)==1&&ia[i]=seq->a[j];
i++;
}
while(strcmp(seq->a[i].card,seq->a[0].card)<0&&ia[j]=seq->a[i];
j--;
}
}while(i!=j);
seq->a[i]=seq->a[0];
quicksort(seq,left,i-1);
quicksort(seq,i+1,right);
}
return seq;
}
int main()
{
int i,n,left,right,l;
seqlist p,*seq;
p=create();
right=p.len;
left=1;
seq=&p;
seqsearch(p);
printf("-----------------------------");
printf("\n按卡号排序的结果如下:\n");
seq=quicksort(seq,left,right);
printf("姓名: 系别: 班号: 卡号:\n");
for(l=1;l<=right;l++)
{
printf("%s ",seq->a[l].name);
printf("%14s ",seq->a[l].department);
printf("%16s ",seq->a[l].classnumber);
printf("%16s \n\n",seq->a[l].card);
}
return 0;
}
```
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
The issue shows a C program for a library management system with a quicksort function that likely has a bug in the comparison logic (strcmp usage). Start by examining the quicksort function in the provided code, particularly the strcmp comparisons and the pivot handling. Run the program to see the sorting output, then debug by checking array indices and string comparisons. The goal is to fix the sorting so it correctly orders records by card number.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- c
- Bereich
- cli
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100