17070047 / 17070047/CodeStructureCourse

1707004714陈琳琳,排序

Offen
#95 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C++
Sterne
16
Forks
2
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
c
Bereich
cli
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.