17070047 / 17070047/CodeStructureCourse

王心如

Đang mở
#83 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
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"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)

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 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.

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ó
2/5
Thời gian dự kiến
1-3 giờ
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
55/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.