17070047 / 17070047/CodeStructureCourse
王心如
- Dominant language
- C++
- Stars
- 16
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
```c
#include"stdio.h"
#include"string.h"
#include"stdlib.h"
#define MAXSIZE 100
typedef int keytype;
typedef struct{
keytype key; //学号
keytype ckey;//班级
char name[20];
}recordtype;
typedef struct{
recordtype r[MAXSIZE+1];
int length;
}table;
void quicksort(table *tab,int left,int right)
{
int i,j;
if(leftr[0]=tab->r[i];
do
{
while(tab->r[j].key>tab->r[0].key&&ir[i].key=tab->r[j].key ;
i++;
}
while(tab->r[i].keyr[0].key&&ir[j].key=tab->r[i].key;
j--;
}
}
while(i!=j);
tab->r[i]=tab->r[0];
quicksort(tab,left,i-1);
quicksort(tab,i+1,right);
}
}
void create(table *tab)
{
int j;
//tab=(table*)malloc(sizeof(table));
printf("请输入学生人数:\n");
scanf("%d",&tab->length);
printf("输入信息:\n") ;
for(j=1;j<=tab->length;j++)
{
printf("姓名:");
scanf("%s",&tab->r[j].name);
printf("班级:");
scanf("%d",&tab->r[j].ckey);
printf("学号:");
scanf("%d",&tab->r[j].key);
}
}
void print(table *tab)
{
printf("姓名\t\t");
printf("班级\t\t");
printf("学号\t\t\n");
for(int i=1;i<=tab->length;i++)
{
printf("%s\t\t",tab->r[i].name) ;
printf("%d\t\t",tab->r[i].ckey);
printf("%d\t\t\n",tab->r[i].key);
}
}
void choose()
{
printf("请选择操作\n") ;
printf("1:创建\n");
printf("2:排序\n");
printf("3:输出\n");
printf("4:查找\n");
}
void search(table *tab)
{
char na[20];
int j=0;
printf("输入要查找的姓名:");
scanf("%s",&na);
for(int i=1;i<=tab->length;i++)
{
if(!strcmp(na,tab->r[i].name))
{
printf("姓名\t\t");
printf("班级\t\t");
printf("学号\t\t\n");
printf("%s\t\t",tab->r[i].name) ;
printf("%d\t\t",tab->r[i].ckey);
printf("%d\t\t\n",tab->r[i].key);
j++;
}
}
if(!j)
{
printf("不存在");
}
}
int main()
{
int i;
table tab;
choose();
while(scanf("%d",&i)!=EOF)
{
switch(i)
{
case 1:create(&tab);
case 2:
quicksort(&tab,1,tab.length);break;
case 3:
print(&tab);break;
case 4:
search(&tab);break;
default:printf("请重新输入!");
}
choose();
}
return 0;
}
```

Contributor guide
No contributing guide indexed for this repository
Research direction
The issue shows a C program with a quicksort implementation that sorts student records by key (student ID). The bug likely involves the sorting logic or data handling, as the code is provided but the expected behavior isn't described. Start by examining the quicksort function in the provided code, particularly the swap operations and pivot handling. Run the program to see if it crashes or sorts incorrectly, then debug by checking array bounds and data assignments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100