Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct noeud //structure liste chaînée
- {
- int valeur; // contenu de la valeur du noeud (ex 50,70,...)
- struct noeud *next; // case du prochain element (=NULL si fin de la liste sinon c
- };
- void afficher(struct noeud *pointeurTeteListe);
- struct noeud *ajouterElementDebut(struct noeud *pointeurTmp, int nouvelleValeur);
- void ajouterElementFin(struct noeud *pointeurTmp, int nouvelleValeur);
- struct noeud *supprimerElement(struct noeud *pointeurTmp, int nouvelleValeur);
- int main()
- {
- struct noeud *pointeurTeteListe=NULL;
- struct noeud *pointeurNouvelElement;
- //nouvel élément de valeur 70
- pointeurNouvelElement=malloc(sizeof(struct noeud));
- pointeurNouvelElement->valeur=70;
- pointeurNouvelElement->next=pointeurTeteListe; // nan c'est bon réesaye
- pointeurTeteListe=pointeurNouvelElement;
- //nouvel élément de valeur 50
- pointeurNouvelElement=malloc(sizeof(struct noeud));
- pointeurNouvelElement->valeur=50;
- pointeurNouvelElement->next=pointeurTeteListe;
- pointeurTeteListe=pointeurNouvelElement;
- afficher (pointeurTeteListe);
- pointeurTeteListe = ajouterElementDebut(pointeurNouvelElement, 5);
- afficher(pointeurTeteListe);
- ajouterElementFin(pointeurNouvelElement, 1911);
- afficher(pointeurTeteListe);
- supprimerElement(pointeurTeteListe, 5);
- afficher(pointeurTeteListe);
- return 0;
- }
- void afficher(struct noeud *pointeurTeteListe)//fonction d'affichage des listes chaînée
- {
- struct noeud *pointeurLecture=pointeurTeteListe; // <= ce pointeur la
- while(pointeurLecture!=NULL)
- {
- printf("%d", pointeurLecture->valeur);
- if(pointeurLecture->next!=NULL)
- {
- printf(";");
- }
- else
- {
- printf("\n");
- }
- pointeurLecture=pointeurLecture->next;
- }
- }
- struct noeud *ajouterElementDebut(struct noeud *pointeurTmp, int nouvelleValeur)//Ajout d'un élément en le placant au début
- {
- struct noeud *pointeurNouvelElement=malloc(sizeof(struct noeud));
- pointeurNouvelElement->valeur=nouvelleValeur;
- pointeurNouvelElement->next=pointeurTmp;
- pointeurTmp=pointeurNouvelElement;
- return pointeurTmp;
- }
- void ajouterElementFin(struct noeud *pointeurTmp, int nouvelleValeur)
- {
- struct noeud *pointeurNouvelElement=malloc(sizeof(struct noeud));
- pointeurNouvelElement->valeur=nouvelleValeur;
- pointeurNouvelElement->next=NULL;
- struct noeud *pointeurTeteListe=pointeurTmp;
- while(pointeurTeteListe->next != NULL)
- {
- pointeurTeteListe=pointeurTeteListe->next;
- }
- pointeurTeteListe->next = pointeurNouvelElement;
- }
- struct noeud *supprimerElement(struct noeud *pointeurTmp, int nouvelleValeur)
- {
- struct noeud *pLecture = pointeurTmp;
- struct noeud *pTrouve = NULL;
- while (pLecture != NULL)
- {
- if(pLecture->valeur == nouvelleValeur)
- {
- pTrouve = pLecture;
- }
- pLecture = pLecture->next;
- }
- if (pTrouve != NULL)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement