#include #include #include #include struct node { /* donnees */ char name[10]; float tevent; /* lien */ struct node *p_suivant; }; typedef struct { struct node *p_debut; struct node *p_courant; } list_s; /*-------------definition des fonctions-----------*/ static void insert (list_s * p_events, char event[10]) { struct node *prec, *nouveau; int choix; /*creation de la liste*/ p_events->p_debut = malloc (sizeof *p_events->p_debut); p_events->p_courant = p_events->p_debut; printf ("\n\nEtrez nom de l'evenement:"); scanf ("%s", event); strcpy (p_events->p_courant->name, event); printf ("\nentez le temps de l'evenement:"); { float tps; scanf ("%f", &tps); p_events->p_courant->tevent = tps; } p_events->p_courant->p_suivant = NULL; do { printf ("\n Autre saisie? o/n"); choix = getchar (); if (choix == 'o' || choix == 'O') { goto nouv; } else { goto fin; } nouv: nouveau = malloc (sizeof *nouveau); printf ("\n\nEtrez nom de l'evenement:"); scanf ("%s", event); strcpy (nouveau->name, event); printf ("\nentez le temps de l'evenement:"); { float tps; scanf ("%f", &tps); nouveau->tevent = tps; } if (nouveau->tevent <= p_events->p_debut->tevent) { nouveau->p_suivant = p_events->p_debut; p_events->p_debut = nouveau; } else { p_events->p_courant = p_events->p_debut; while (p_events->p_courant->p_suivant != NULL) { p_events->p_courant = p_events->p_courant->p_suivant; } if (nouveau->tevent >= p_events->p_courant->tevent) { nouveau->p_suivant = NULL; p_events->p_courant->p_suivant = nouveau; } else { p_events->p_courant = p_events->p_debut; prec = p_events->p_courant; while (p_events->p_courant != NULL) { if (nouveau->tevent <= p_events->p_courant->tevent) { prec->p_suivant = nouveau; nouveau->p_suivant = p_events->p_courant; } prec = p_events->p_courant; p_events->p_courant = p_events->p_courant->p_suivant; } } } } while (choix == 'o' || choix == 'O'); fin: ; } static void affichage (list_s const *p_events) { struct node *p_node = p_events->p_debut; if (p_events->p_debut == NULL) { printf ("la liste est vide"); } while (p_node != NULL) { printf ("\n name:%s", p_node->name); printf ("\ntevent:%.2f", p_node->tevent); p_node = p_node->p_suivant; } } static void extract (list_s * p_events) { if (p_events->p_debut == NULL) { printf ("la liste est vide"); } else { struct node *p_old = p_events->p_debut; printf ("\nl'element supprime est :%s %.2f", p_old->name, p_old->tevent); p_events->p_debut = p_old->p_suivant; free (p_old); } } static int menuprincipal (void) { int menu; printf ("1.insertion\n" "2.consultation\n" "3.suppression\n" "4.quitter l'application"); printf ("\nchoix menu:"); scanf ("%d", &menu); return menu; } int main (void) { int menu; list_s events = { 0 }; do { char e[10]; menu = menuprincipal (); switch (menu) { case 1: /*appel … la fonction insertion */ insert (&events, e); break; case 2: /*consultation de la liste chainee */ affichage (&events); break; case 3: /*suppression du premier element */ extract (&events); break; } /*fin de switch case */ } while (menu != 4); return 0; }