17070047 / 17070047/CodeStructureCourse
潘瑞
- Dominant language
- C++
- Stars
- 16
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
```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;
}
```

Contributor guide
No contributing guide indexed for this repository
Research direction
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.
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
- 40/100