Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct student {
- char nom[25];
- int age;
- };
- struct list_student {
- struct student Letudiant;
- struct list_student * suivant;
- };
- struct list_student * ajout_etudiant (struct student S, struct list_student *L) {
- struct list_student * res = NULL;
- res = (struct list_student *)malloc(sizeof(struct list_student));
- res->Letudiant = S;
- res->suivant = L;
- return res;
- }
- void afficher_etudiant(struct student E) {
- printf("%s\n", E.nom);
- printf("%d\n",E.age);
- }
- void afficher_element(struct list_student *el) {
- afficher_etudiant(el->Letudiant);
- }
- void afficher_list(struct list_student *el) {
- while(el!=NULL)
- {
- afficher_element(el);
- el = el->suivant;
- }
- }
- struct list_student * creer_liste ()
- {
- struct list_student * resultat = NULL;
- struct student s1 = {"Isabelle", 19};
- struct student s2 = {"Daniel", 23};
- struct student s3 = {"Alexandre", 25};
- struct student s4 = {"Marie", 17};
- struct student s5 = {"Bruno", 27};
- struct student s6 = {"Antoine", 15};
- struct student s7 = {"Jean", 22};
- struct student s8 = {"Clement", 23};
- struct student s9 = {"Diego", 24};
- struct student s0 = {"Caroline", 16};
- resultat = ajout_etudiant (s1, resultat);
- resultat = ajout_etudiant (s2, resultat);
- resultat = ajout_etudiant (s3, resultat);
- resultat = ajout_etudiant (s4, resultat);
- resultat = ajout_etudiant (s5, resultat);
- resultat = ajout_etudiant (s6, resultat);
- resultat = ajout_etudiant (s7, resultat);
- resultat = ajout_etudiant (s8, resultat);
- resultat = ajout_etudiant (s9, resultat);
- resultat = ajout_etudiant (s0, resultat);
- return resultat;
- }
- struct list_student * supprimer_elements (int N1, int N2, struct list_student * L)
- {
- int lisLong = 0;
- struct list_student * Ltemp = L;
- while(Ltemp!=NULL)
- {
- Ltemp = Ltemp->suivant;
- lisLong++;
- }
- lisLong = lisLong - 1;
- if(L!=NULL && N2>=N1 && N2<=lisLong)
- {
- int i = 0;
- struct list_student * Ldebut;
- Ldebut=(struct list_student*)malloc(sizeof(struct list_student));
- Ldebut = L;
- while(i<N1-1 && N1!=0)
- {
- Ldebut = Ldebut->suivant;
- i++;
- }
- struct list_student * Lfin;
- Lfin=(struct list_student*)malloc(sizeof(struct list_student));
- Lfin = L;
- i=0;
- while(i<N2)
- {
- Lfin = Lfin->suivant;
- i++;
- }
- Ldebut->suivant = Lfin->suivant;
- if(N1 == 0)
- {
- L = Lfin;
- }
- }
- return L;
- }
- int main() {
- struct list_student * ls = NULL;
- ls = creer_liste ();
- printf("Ancienne: \n");
- afficher_list(ls);
- ls = supprimer_elements(2, 5, ls);
- printf("\nNouvelle:\n");
- afficher_list(ls);
- return 1;
- }
Add Comment
Please, Sign In to add comment