1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #include <stdio.h>
#include <stdlib.h>
typedef struct element * Pelement;
typedef struct liste * Pliste;
typedef struct element{
int x;
Pelement suivant;
}Element;
typedef struct liste{
Pelement premier;
Pelement courant;
Pelement dernier;
}Liste;
void initListe(Pliste L){
L = (Pliste) malloc ( sizeof(Liste));
L->premier = (Pelement) malloc ( sizeof(Element));
L->courant = (Pelement) malloc ( sizeof(Element));
L->dernier = (Pelement) malloc ( sizeof(Element));
L->premier = NULL;
L->courant = NULL;
L->dernier = NULL;
}
void insereUnElemt(Pliste L, Pelement nouveau){
nouveau->suivant = L->premier;
L->premier = nouveau;
if( L->dernier ==NULL )
L->dernier = nouveau;
}
void creeListeDecroissante(Pliste L, int n){
printf("***** creeListeDecroissante() *****\n");
int i;
Pelement Pel;
for(i=1; i<=n; i++){
Pel = (Pelement)malloc( sizeof (Element));
Pel->x = i;
insereUnElemt(L, Pel);
}
}
void afficheListe(Pliste L){
L->courant = L->premier;
while (L->courant != NULL){
printf("%d, ", L->courant->x);
L->courant = L->courant->suivant;
}
}
Liste l;maListe = &l;
int main(){
initListe(maListe);
creeListeDecroissante(maListe, 5);
printf("** afficheListe() ** \n[ ");
afficheListe(maListe);
printf(" ]\n");
return 0;
} |
Partager