17070047 / 17070047/CodeStructureCourse

王心如

Aberta
#83 0 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
C++
Estrelas
16
Forks
2
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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

![49658941-1b8f4e80-fa7e-11e8-8dfb-5a3f7d73da55](https://user-images.githubusercontent.com/32426394/49683073-fb9d7080-faf9-11e8-9309-bdea97f73be9.png)

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
c
Domínio
cli
Tipo de issue
Bug
Dificuldade
2/5
Tempo estimado
1-3 horas
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
55/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.