17070047 / 17070047/CodeStructureCourse

1707004714陈琳琳,排序

Open
#95 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
16
Forks
2
PR merge metrics
No merged PRs in 30d

Description

#include
#include
#include
#define m 100
typedef int keytype;
typedef struct{
int number;//卡号
char name[10];//姓名
char depart[10];//系名
char class_num;//班号
}student;
typedef struct{
student r[m+5];
int length;
}table;
void creat(table *tab)
{
printf("输入总个数:");
scanf("%d",&tab->length);
printf("\n输入每个成员信息:\n");
for(int i=1;i<=tab->length;i++)
{
printf("姓名:");
scanf("%s",&tab->r[i].name);
printf("卡号:");
scanf("%d",&tab->r[i].number);
printf("班号:");
scanf("%s",&tab->r[i].class_num);
printf("系名:");
scanf("%s",&tab->r[i].depart);
printf("\n");
}
}
//直接排序算法
void insertsort(table *tab)
{
int i,j;
for(i=2;i<=tab->length;i++)
{
j=i-1;
tab->r[0]=tab->r[i];
while(tab->r[0].numberr[j].number)
{
tab->r[j+1]=tab->r[j];
j--;
}
tab->r[j+1]=tab->r[0];
}
}
//二分法插入排序算法
void binarysort(table *tab)
{
int i,j,left,right,mid;
for(i=2;i<=tab->length;i++)
{
tab->r[0]=tab->r[i];
left=1;right=i-1;
while(left<=right)
{
mid=(left+right)/2;
if(tab->r[i].numberr[mid].number)
right=mid-1;
else
left=mid+1;
}
for(j=i-1;j>=left;j--)
tab->r[j+1]=tab->r[j];
tab->r[left]=tab->r[0];
}
}
//快速排序
void quicksort(table *tab,int left,int right)
{
int i,j;
if(leftr[0]=tab->r[i];
do{
while(tab->r[j].number>tab->r[0].number&&ir[i]=tab->r[j];i++;
}
while(tab->r[i].numberr[0].number&&ir[j]=tab->r[i];j--;
}
}while(i!=j);
tab->r[i]=tab->r[0];
quicksort(tab,left,i-1);
quicksort(tab,i+1,right);
}
}
void output(student x)
{
printf("姓名:%s 卡号:%d 班号:%s 系名:%s\n",x.name,x.number,x.class_num,x.depart);
}
void outputall(table *tab)
{
for(int i=1;i<=tab->length;i++)
{
printf("姓名:%s 卡号:%d 班号:%s 系名:%s \n",tab->r[i].name,tab->r[i].number,tab->r[i].class_num,tab->r[i].depart);
}
}
void search(table *tab)
{
char s[20];
printf("输入要查找的系名:\n");
scanf("%s",s);
int flag=0;
for(int i=1;i<=tab->length;i++)
{
if(!strcmp(s,tab->r[i].major)){
output(tab->r[i]);flag++;
}
}
if(!flag) printf("不存在\n");
}
void role()
{
printf("1:创建\t2:输出\t3:查找\t0:结束\n");
}
int main()
{
table tab;
int cmd;
role();
while(scanf("%d",&cmd)!=EOF)
{
switch(cmd)
{
case 1:creat(&tab);
case 4:quicksort(&tab,1,tab.length);break;
case 2:outputall(&tab);break;
case 3:search(&tab);break;
case 0:printf("退出成功");return 0;
default:printf("请重新输入!");
}
role();
}
return 0;
}
![vp _ut 2o53 m25x4jfkhv](https://user-images.githubusercontent.com/45326798/49711468-68d80f80-fc7a-11e8-8611-18524b30a767.png)
![m5xmwm f 6tigwsib 8e03](https://user-images.githubusercontent.com/45326798/49711470-6d042d00-fc7a-11e8-8175-5632d0053d87.png)

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue shows a C program with sorting functions and a student record system. The bug likely relates to the search function using 'major' field which isn't defined in the struct (should be 'depart'). Start by examining the struct definition and the search function. Compile the program to see errors, then fix the field name mismatch. Test by creating a few records and searching by department.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.