17070047 / 17070047/CodeStructureCourse

王心如

未关闭
#83 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
C++
星标
16
派生
2
PR 合并指标
30 天内没有已合并 PR

描述

```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)

贡献指南

这个仓库没有索引到贡献指南

调研方向

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.

由索引模型根据 Issue 内容生成。

评估

技术栈
c
领域
cli
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
基本清楚
新手友好度
55/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。