Académique Documents
Professionnel Documents
Culture Documents
{
if (tete == 0)
return 0;
else
return 1;
}
mlmlmlmlmlmlmlmlmlmlmlmlmlmlmlmlmlmlml
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
struct liste
{
int val;
struct liste *suivant;
};
return cpt;
}
}
ptr=ptr->suivant;
}
if (s==0){
printf("--------element n'existe pas -----------\n");
}
}
if (pos==1) {
h=ajouterdebut(h);
} else if(pos==(x+1)) {
h= ajouterfin(h);
} else {
printf("entrer la valeure");
scanf("%d",&nouveau->val);
while(i != (pos-1)) {
h=h->suivant;
i=i+1;
}
nouveau->suivant=h->suivant;
h->suivant=nouveau;
}
return h;
}
struct liste* supprimer(struct liste* w)
{
int pos, i, x;
i = 1;
struct liste* o = w;
struct liste* k = w;
x = comptabiliser(w);
do {
printf("Entrer la position que vous voulez supprimer : ");
scanf("%d", &pos);
} while ( (pos < 1) ||( pos > (x + 1)));
if (pos == 1) {
w = w->suivant;
free(o);
return w;
} else {
while (i != pos) {
o = k;
k = k->suivant;
i = i + 1;
}
o->suivant = k->suivant;
free(k);
return w;
}
}
return NULL;
}
void end(struct liste*r)
{
printf("\n\n\n------- thank you sir that's was great to create this programme
---------\n -----directed by :\n\------");
}
int main()
{
int pos;
int x;
struct liste *tete = NULL;
tete = malloc(sizeof(struct liste));
struct liste *ptr = tete;
tete = creeuneliste(tete);
afficher(tete);
ptr=ajouteposition(ptr);
afficher(tete);
tete = ajouterdebut(tete);
afficher(tete);
ptr = ajouterfin(ptr);
afficher(tete);
x=comptabiliser(tete);
printf(" la taille de votr liste est %d\n",x);
recherche(tete);
tete=supprimer(tete);
afficher(tete);
tete=detruire_liste(tete);
afficher(tete);
end(tete);
return 0;
}
bideractionelle
-----------------------------------------------------------------------------------
----------------------
/*--------------------------------------------- biderectionele
--------------------------------------------------------------------------------*/
/*
void verif(Liste L)
{
if ((L.head==NULL) || (L.taille==0))
printf("la liste est vide \n");
else printf("la liste n'est pas vide \n");
}
for(i=0;i<liste->taille;i++)
{
temp=malloc(sizeof(Element));
printf("rentrez la valeur de l'element num %d \n ",i+1);
scanf("%d",&temp->valeur);
temp->suivant=NULL;
temp->precedent=NULL;
if (liste->head==NULL)
{
liste->head=temp;
}
else
{
p=liste->head;
if(p->suivant == NULL)
{
p->suivant = temp;
temp->precedent = p;
}
else
{
while (p->suivant!=NULL)
{
p=p->suivant;
}
p->suivant=temp;
temp->precedent=p;
}
}
}
}
Element *p;
p=NULL;
p=liste.head;
for(i=0;i<liste.taille;i++)
{
printf("la valeur de l'element num %d : %d \n",i+1,p->valeur);
p=p->suivant;
q=malloc(sizeof(Element));
q->valeur=x;
q->suivant=NULL;
q->precedent=NULL;
if (liste->head==NULL) // ou taille = 0;
{
liste->head=q;
}
else
{
q->suivant=liste->head;
liste->head=q;
}
liste->taille=liste->taille+1;
}
if (liste->taille == 0)
{
ajoutdebut(liste,val);
}
else
{
q=malloc(sizeof(Element));
q->valeur=val;
q->suivant=NULL;
q->precedent=NULL;
p=liste->head;
while (p->suivant!=NULL)
{
p=p->suivant;
}
p->suivant=q;
q->precedent=p;
liste->taille++;
}
}
int i;
Element *p,*q,*t;
p=NULL;
q=NULL;
t=NULL;
q=malloc(sizeof(Element));
q->valeur=val;
q->suivant=NULL;
if (pos> liste->taille+1 )
{printf("ERREUR aucun element dans cette position \n\n");
return;}
else if (pos==1){ajoutdebut(liste,val); return;}
else if (pos==liste->taille+1){ajoutfin(liste,val);return;}
else
{
p=liste->head;
for(i=1;i<pos;i++)
{
t=p;
p=p->suivant;
}
t->suivant=q;
q->precedent=t;
q->suivant=p;
p->precedent=q;
liste->taille++;
}
void trierliste(Liste *liste)
{
int i, j, n, m;
Element *p, *q;
q= NULL;
p= NULL;
n= liste->taille;
q= liste->head;
if(p==NULL){ajoutfin(liste,val);return;}
q->precedent=r;
p->precedent=q;
r->suivant=q;
q->suivant=p;
liste->taille++;
}
if (p->valeur==val){trouv=true;}
p=p->suivant;
}
}
if (trouv==true) {printf("l'élement se trouve dans la liste \n");}
else {printf("l'élement ne se trouve pas dans la list \n ");}
}
p=liste->head;
if (pos==1) {
liste->head=p->suivant;
if (liste->head!=NULL) {
liste->head->precedent=NULL;
}
free(p);
} else {
q=NULL;
int i;
for (i=1;i<pos;i++) {
q=p;
p=p->suivant;
}
q->suivant=p->suivant;
if (p->suivant!=NULL) {
p->suivant->precedent=q;
}
free(p);
}
liste->taille--;
}
*/