17070047 / 17070047/CodeStructureCourse
潘瑞
- Ngôn ngữ chính
- C++
- Star
- 16
- Fork
- 2
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
```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;
}
```

Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- c
- Lĩnh vực
- cli
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 40/100