Tri file

kakitn Messages postés 12 Date d'inscription vendredi 21 décembre 2007 Statut Membre Dernière intervention 28 décembre 2008 - 27 déc. 2008 à 18:09
kakitn Messages postés 12 Date d'inscription vendredi 21 décembre 2007 Statut Membre Dernière intervention 28 décembre 2008 - 28 déc. 2008 à 02:25
salut, j'ais une file (liste simplement chainée) de candidats, chaque candidats est identifié par un nom, prenom, genre et un score.
je veux ecrire une fonction qui permet de trier cette liste dans l'ordre decroissant
pouvez vous m'aider svp!

voila un bout du code :

typedef struct candidat
{
char nom[20];
char prenom[20];
char genre;
float score;
struct candidat *suivant;
}candidat;

typedef struct file
{
candidat *debut;
candidat *fin;
int taille;
}file;

void enfiler(file *f, char n[20], char pn[20], char g, float s)
{
candidat *c=(candidat*)malloc(sizeof(candidat));
strcpy(c->nom,n);
strcpy(c->prenom,pn);
c->genre = g;
c->score = s;
c->suivant = NULL;
if (f->fin!=NULL)
{
f->fin->suivant = c;
f->fin = c;
}
else
{
f->debut = c;
f->fin = c;
}
f->taille++;
printf("*** candidat %d enregistre ***\n\n",f->taille);
}

merci d'avance!

1 réponse

kakitn Messages postés 12 Date d'inscription vendredi 21 décembre 2007 Statut Membre Dernière intervention 28 décembre 2008
28 déc. 2008 à 02:25
salut, j'ais une file (liste simplement chainée) de candidats, chaque candidats est identifié par un nom, prenom, genre et un score. je veux ecrire une fonction qui permet de trier cette liste dans l'ordre decroissant pouvez vous m'aider svp! voila un bout du code :
typedef struct candidat {
char nom[20]; char prenom[20];
char genre; float score;
struct candidat *suivant;
}candidat;

typedef struct file {
candidat *debut; candidat *fin;
int taille;
}file;

void enfiler(file *f, char n[20], char pn[20], char g, float s) {
candidat *c=(candidat*)malloc(sizeof(candidat)); strcpy(c->nom,n);
strcpy(c->prenom,pn);
c->genre = g;
c->score = s;
c->suivant = NULL;
if (f->fin!=NULL) {
f->fin->suivant c; f->fin c; }
else { f->debut c; f->fin c; }
f->taille++;
printf("*** candidat %d enregistre ***\n\n",f->taille);
}

merci d'avance!
0
Rejoignez-nous