17070047 / 17070047/CodeStructureCourse

潘瑞

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

Beschreibung

```c

#include
#include
#include
#define M 20
typedef struct{
int xuehao;
char xingming[M];
char zhuanye[M];
int banhao;
}xinxi;
typedef struct{
xinxi student[M-1];
int len;
}students;
students *creat(int n)
{
int i;
students *s;
s = (students *)malloc(sizeof(students));
s->len=0;
printf("姓名\t学号\t专业\t班号:\n");
for (i=1; i<=n; i++)
{
scanf("%s%d%s%d", &s->student[i].xingming,&s->student[i].xuehao,&s->student[i].zhuanye,&s->student[i].banhao);
s->len++;
}
return s;
}
//排序
students* quicksort(students *tab,int left,int right)
{
int i,j;
if(leftstudent[0]=tab->student[i];
do
{
while(tab->student[j].xuehao>tab->student[0].xuehao&&istudent[i]=tab->student[j];
i++;
}
while(tab->student[i].xuehaostudent[0].xuehao&&istudent[j]=tab->student[i];
j--;
}
}while(i!=j);
tab->student[i]=tab->student[0];
quicksort(tab,left,i-1);
quicksort(tab,i+1,right);
}
return tab;
}
//顺序检索
void seqsever(students *s,char zhuanye[M])
{
int k;
printf("顺序检索结果为:\n");
for(k=1;k<=s->len;k++)
{
if(strcmp(s->student[k].zhuanye,zhuanye)==0)
printf("%s\t%d\t%s\t%d\n",s->student[k].xingming,s->student[k].xuehao,s->student[k].zhuanye,s->student[k].banhao);
}
}
//二分法检索非递归
int binsearch1(students *s,int key)
{
int low=1,high=s->len,mid;
while(low<=high)
{
mid=(low+high)/2;
if(s->student[mid].xuehao==key)
{
printf("二分法检索结果为:\n");
printf("%s\t%d\t%s\t%d\n",s->student[mid].xingming,s->student[mid].xuehao,s->student[mid].zhuanye,s->student[mid].banhao);
}
if(s->student[mid].xuehao>key)
high=mid-1;
else
low=mid+1;
}
return -1;
}

int main()
{
students *p;
int key,i,n;
char zhuanye[M];
p = (students *)malloc(sizeof(students));
printf("请输入你需要输入的信息的个数:");
scanf("%d", &n);
getchar();
p=creat(n);
//快速排序
p=quicksort(p,0,p->len);
printf("\n按学号排序输出结果为:\n");
for (i=1; i<=p->len; i++)
printf("%s\t%d\t%s\t%d\n",p->student[i].xingming,p->student[i].xuehao,p->student[i].zhuanye,p->student[i].banhao);
//顺序检索
getchar();
printf("\n请输入需要查找的专业:");
scanf("%s",&zhuanye);
//gets(zhuanye);
seqsever(p,zhuanye);
//二分法检索
printf("\n请输入需要查找的学号:");
scanf("%d",&key);
binsearch1(p,key);
return 0;
}
```
![default](https://user-images.githubusercontent.com/45326733/49681201-a00ebb00-fad8-11e8-986d-b292071fcc5c.png)

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

The issue contains a C program for student information management with sorting and search functions. The bug is not explicitly stated, but the code likely has issues like array indexing starting at 1, potential buffer overflows, or logic errors in quicksort or binary search. Start by examining the main.c file (or similar) in the repository to see the context. Run the program with sample inputs to identify crashes or incorrect outputs. Focus on the quicksort implementation and array bounds, as student array uses indices 1 to M-1.

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
40/100

Neue Issues direkt in Ihr Postfach

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