Langage c
Fermé
omzyaser
-
19 févr. 2011 à 17:36
jisisv Messages postés 3645 Date d'inscription dimanche 18 mars 2001 Statut Modérateur Dernière intervention 15 janvier 2017 - 19 févr. 2011 à 19:45
jisisv Messages postés 3645 Date d'inscription dimanche 18 mars 2001 Statut Modérateur Dernière intervention 15 janvier 2017 - 19 févr. 2011 à 19:45
A voir également:
- Langage c
- D langage c ✓ - Forum C
- Langage ascii - Guide
- Et en langage c - Astuces et Solutions
- Langage linux - Forum Linux / Unix
- Mini projet en langage c corrigé - Forum C
1 réponse
jisisv
Messages postés
3645
Date d'inscription
dimanche 18 mars 2001
Statut
Modérateur
Dernière intervention
15 janvier 2017
947
19 févr. 2011 à 19:45
19 févr. 2011 à 19:45
Essaye ceci (je n'ai pas tout testé !!)
Johan
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/*
*
*inserer dans une liste ordonnée
*
*/
typedef struct Personne{
struct Personne *svt;
int val;
char *nom;
} Personne;
Personne *insertion(Personne **premier, char *nom, int val){
Personne *p=(Personne *)malloc(sizeof(Personne));
if(NULL == p)
return NULL;
else{
p->nom = nom;
p->val = val;
if(NULL == *premier){
p->svt = NULL;
*premier = p;
return p;
}
else{
Personne *p2 = *premier;
Personne *p3 = (*premier)->svt;
while ( (strcmp(p2->nom,nom)<0) && (NULL != p3) && (strcmp(nom,p3->nom)>0)) {
p2 = p2->svt;
p3 = p3->svt;
}
p->svt=p3;
p2->svt=p;
}
return p;
}
}
int main(int argc, char *argv[]) {
Personne *liste = NULL, *qqun;
qqun = insertion( &liste, "Brian Kernighan", 1942);
qqun = insertion( &liste, "Linus Torvalds", 1969);
qqun = insertion( &liste, "James Gosling", 1955);
if(NULL != qqun) {
printf("%s\n", liste->svt->nom);
// doit afficher "James Gosling"
}
return 0;
}
johand@osiris:~/src/ccm$ gcc -Wall -o 20916919-langage-c -g 20916919-langage-c.c
johand@osiris:~/src/ccm$ ./20916919-langage-c
James Gosling
Johan