#include<stdlib.h>
#include<stdio.h>
#include<stdbool.h>
struct Cellule {
struct Cellule* suiv;
int val;
};
typedef struct Cellule Cellule;
void ajout_tete(Cellule** l, int val) {
Cellule* p;
p = malloc(sizeof(Cellule));
p->val = val;
p->suiv = *l;
*l = p;
}
void imprimer(Cellule* l) {
while (l != NULL) {
printf("%d\n", l->val);
l = l->suiv;
bool est_trie(Cellule* l) {
if (l == NULL) {
return true;
int temp;
while (l->suiv != NULL) {
temp = l->val;
if (l->val < temp) {
return false;
void supprimer_tete(Cellule** l) {
p = (*l)->suiv;
free(*l);
void desallouer(Cellule** l) {
while ((*l)->suiv != NULL) {
supprimer_tete(l);
void inserer(Cellule** p, int val) {
Cellule* l = *p;
ajout_tete(p, val);
return;
while (l->suiv != NULL && l->val < val) {
p = &l->suiv;
if (l->val == val) {
} else if (l->val < val) {
int main(int argc, char* argv[]) {
if (argc != 2) {
printf("Usage : %s FICHIER_ENTREE\n", argv[0]);
return EXIT_FAILURE;
FILE* fp;
fp = fopen(argv[1], "r");
if (fp == NULL) {
printf("Impossible d'ouvrir le fichier %s.\n", argv[1]);
Cellule* l = NULL;
while (fscanf(fp, "%d", &val) != EOF) {
inserer(&l, val);
imprimer(l);
if (!est_trie(l)) {
printf("Erreur: La liste n'est pas correctement triée.\n");
return EXIT_SUCCESS;