Files
AndroidStudioProjects
Automate
ControleMachine1
ControleMachine2
ControleMachineJava
DEV1.1
TP01:Commandes,Entier
TP02:Caracteres,Reels
TP03:Conditions
TP04:Types
TP05:Boucles
TP06:Tableaux
TP07:ChaineDeCaracteres
TP08:Adresses
TP09:AllocationDynamique
TP10:Fonctions
TP11:Debogueur
TP12:Structures
TP13:Fichiers
TP14:BiblioGraph
TP15:ListesChainees
circulation.c
maximum.c
TP16:Recursivite
TP17:Pile
DEV2.1
DEV3.1
DEV3.2
DEV3.4
DEV32
DEV4.4
SAe
.gitignore
Ex1TP2.mdj
README.md
Vote.java
pourchot_dev32.tar.gz
DEV/DEV1.1/TP15:ListesChainees/circulation.c

82 lines
1.9 KiB
C
Raw Normal View History

2022-12-13 11:28:10 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct maillon {
unsigned short valeur;
struct maillon* suiv;
};
typedef struct maillon maillon;
maillon* ajouteDebut(maillon *chaine, unsigned short entier){
maillon *nouveauMaillon=malloc(sizeof(maillon));
nouveauMaillon->valeur=entier;
nouveauMaillon->suiv=chaine;
return nouveauMaillon;
}
maillon* retireDebut(maillon *chaine){
maillon *premierMaillon=malloc(sizeof(maillon));
maillon *nouvelleChaine=malloc(sizeof(maillon));
premierMaillon=chaine;
nouvelleChaine=premierMaillon->suiv;
premierMaillon->suiv=NULL;
free(premierMaillon);
return nouvelleChaine;
}
void ajouterFin(maillon *chaine, unsigned short entier){
maillon *nouveauMaillon=malloc(sizeof(maillon));
nouveauMaillon->valeur=entier;
nouveauMaillon->suiv=NULL;
maillon *parcourir=malloc(sizeof(maillon));
parcourir=chaine;
while(parcourir->suiv!=NULL){
parcourir=parcourir->suiv;
}
parcourir->suiv=nouveauMaillon;
}
void retireFin(maillon *chaine){
maillon *parcourir=malloc(sizeof(maillon));
maillon *precedent=malloc(sizeof(maillon));
precedent->suiv=NULL;
parcourir=chaine;
while(parcourir->suiv!=NULL){
precedent=parcourir;
parcourir=parcourir->suiv;
} precedent->suiv=NULL;
free(parcourir);
free(precedent);
}
void afficheListe(maillon *chaine){
maillon *affichage=malloc(sizeof(maillon));
affichage=chaine;
while(affichage->suiv!=NULL){
printf("%hu ",affichage->valeur);
affichage=affichage->suiv;
} printf("\n\n");
free(affichage);
}
int main() {
int i;
maillon *liste=malloc(sizeof(maillon));
srand(time(NULL));
putchar('\n');
liste->valeur=(rand()%889)+111;
liste->suiv=NULL;
for(i=0;i<10;i++){
unsigned short v=(rand()%889)+111;
liste=ajouteDebut(liste, v);
} printf("Les valeurs de la liste sont :\n");
afficheListe(liste);
unsigned short v=(rand()%889)+111;
ajouterFin(liste, v);
printf("Les valeurs de la liste sont :\n");
afficheListe(liste);
return 0;
}