17070047 / 17070047/CodeStructureCourse

赵玉洁

Offen
#64 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

# Code
```C
#include
#include
#define MAXSIZE 100
typedef struct
{
int no;//序号
long key;//卡号
char xi[50];//系号
char name[50];//名字
int classes;//班级
}recordtype;
typedef struct
{
recordtype r[MAXSIZE];
int length;
}table;

void QuickSort(table *tab,int left,int right)
{
int i,j;
if(leftr[0]=tab->r[i];
do
{
while(ir[j].key>tab->r[0].key) j--;
if(ir[i]=tab->r[j];
i++;
}
while(ir[i].keyr[0].key) i++;
if(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 creat(table *g)
{
int i,j=1;
printf("输入i,不等于一千可以持续输入\n");
scanf("%d",&i);
g->length=0;
while(i!=1000)
{
g->r[j].no = j;
printf("输入卡号\n");
scanf("%ld",&g->r[j].key);
printf("输入姓名\n");
scanf("%s",&g->r[j].name);
printf("输入系别\n");
scanf("%s",&g->r[j].xi);
printf("输入班级\n");
scanf("%d",&g->r[j].classes);
g->length++;
j++;
printf("输入i,不等于一千可以持续输入\n");
scanf("%d",&i);
}
}
void search(table *l)
{
int k,i;
k=l->length;
char finding[8];
printf("输入要检索的系别;\n");
scanf("%s",&finding);
for(i=1;i<=k;i++)
{
if(strcmp(l->r[i].xi,finding)==0)
{
printf("%d\n",l->r[i].key);
}
}
}
void main()
{
table tab;
int i;
creat(&tab);
QuickSort(&tab,1,tab.length);
printf("学号 姓名 系别 班级 \n");
for(i=1;i<=tab.length;i++)
{
printf("%ld %s %s %d\n",tab.r[i].key,tab.r[i].name,tab.r[i].xi,tab.r[i].classes);
}
search(&tab);
}

```

# Result

![default](https://user-images.githubusercontent.com/45332057/49649393-ff7eb380-fa63-11e8-99bc-5dfc353b57a4.png)

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

The issue shows a C program for sorting and searching student records. The code includes a QuickSort implementation and a search function. Start by examining the main function in the provided code to understand the data flow. Look for potential bugs in the sorting logic or input handling, and run the program to reproduce the issue shown in the image. Check for memory issues, off-by-one errors in array indexing (since it uses 1-based indexing), and ensure string comparisons work correctly.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
c
Bereich
cli
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
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.