17070047 / 17070047/CodeStructureCourse

段玉兰

Open
#67 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
16
Forks
2
PR merge metrics
No merged PRs in 30d

Description

```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;
}
```

default

Contributor guide

No contributing guide indexed for this repository

Research direction

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.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.