35 lines
773 B
C
35 lines
773 B
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
struct liste {
|
|
struct liste* suivant;
|
|
int valeur;
|
|
};
|
|
typedef struct liste liste_t;
|
|
|
|
// Alloue une nouvelle cellule de
|
|
// valeur `val`
|
|
liste_t* alloc_cell(int val) {
|
|
liste_t* cell =
|
|
malloc(sizeof(liste_t));
|
|
cell->valeur = val;
|
|
cell->suivant = NULL;
|
|
return cell;
|
|
}
|
|
|
|
// Affiche les `taille` 1ères valeurs de `liste`
|
|
void afficher_liste(liste_t* liste, int taille) {
|
|
liste_t* cur = liste;
|
|
for(int pos=0; pos < taille; ++pos) {
|
|
printf("%d\n", cur->valeur);
|
|
cur = cur->suivant;
|
|
}
|
|
}
|
|
int main(int argc, char** argv) {
|
|
int n = atoi(argv[1]); // premier argument
|
|
liste_t* tete = alloc_cell(1);
|
|
tete->suivant = alloc_cell(2);
|
|
afficher_liste(tete, n);
|
|
return 0;
|
|
}
|