probleme d affichage une liste chainee
Dernière réponse : dans Programmation
salut
j ai un probleme lors d affichage d une liste chaine. le probleme lors d inserer les valeur par exemple j insere 5 et 7 et 8 dans l affichage je trouve 8 8 8
la valeur 8 se repete 3 fois :
voici mon script d affichage liste chainée :
void affichage(liste *adl)
{
Tnoeud *p ;
p=adl->debut ;
do
{
printf("%d",x);
p=p->suiv ;
}
while((p->suiv)!=NULL);
}
s il y a quelqu un peut corriger la procedure affichage .
merci d avance
j ai un probleme lors d affichage d une liste chaine. le probleme lors d inserer les valeur par exemple j insere 5 et 7 et 8 dans l affichage je trouve 8 8 8
la valeur 8 se repete 3 fois :
voici mon script d affichage liste chainée :
void affichage(liste *adl)
{
Tnoeud *p ;
p=adl->debut ;
do
{
printf("%d",x);
p=p->suiv ;
}
while((p->suiv)!=NULL);
}
s il y a quelqu un peut corriger la procedure affichage .
merci d avance
Autres pages sur : probleme affichage liste chainee
Lassé par la pub ? Créez un compte
voici mon programme :
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct tnoeud {
int ele ;
struct tnoeud *suiv ;
} Tnoeud ;
typedef struct {
Tnoeud *debut ;
Tnoeud *fin ;
int lg ;
}liste ;
liste *adl ;
int n,i,x,lg;
char rep ;
/*creer un noeud */
Tnoeud * creer_noeud (int x)
{
Tnoeud *p ;
p= (Tnoeud * )malloc (sizeof(Tnoeud));
if (p)
{
p->ele = x ;
p->suiv = NULL ;
}
return p ;
}
void initialiser (liste *adl)
{
adl->debut=NULL ;
adl->fin=NULL;
adl->lg = 0 ;
}
void inserer ( liste *adl , int x )
{
Tnoeud *p = creer_noeud(x);
if (p)
{
adl->debut = adl->fin = p ;
adl->lg+=1;}
else
{
adl->fin->suiv = p;
adl->fin = p ;
adl->lg+=1;
}
printf("la longeur est : %d \n",adl->lg);
}
void affichage(liste *adl)
{
Tnoeud *p ;
p=adl->debut ;
do
{
printf("%d",x);
p=p->suiv ;
}
while((p->suiv)!=NULL);
}
void main ()
{
clrscr();
/* apel fonction inserer*/
initialiser(adl);
do{
printf("entrer une valeur : ");
scanf("%d",&x);
inserer(adl,x);
printf("voulez vous inserer: ");
scanf("%s",&rep);
}
while(rep=='o');
/*affichage*/
affichage(adl);
getch();
}
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct tnoeud {
int ele ;
struct tnoeud *suiv ;
} Tnoeud ;
typedef struct {
Tnoeud *debut ;
Tnoeud *fin ;
int lg ;
}liste ;
liste *adl ;
int n,i,x,lg;
char rep ;
/*creer un noeud */
Tnoeud * creer_noeud (int x)
{
Tnoeud *p ;
p= (Tnoeud * )malloc (sizeof(Tnoeud));
if (p)
{
p->ele = x ;
p->suiv = NULL ;
}
return p ;
}
void initialiser (liste *adl)
{
adl->debut=NULL ;
adl->fin=NULL;
adl->lg = 0 ;
}
void inserer ( liste *adl , int x )
{
Tnoeud *p = creer_noeud(x);
if (p)
{
adl->debut = adl->fin = p ;
adl->lg+=1;}
else
{
adl->fin->suiv = p;
adl->fin = p ;
adl->lg+=1;
}
printf("la longeur est : %d \n",adl->lg);
}
void affichage(liste *adl)
{
Tnoeud *p ;
p=adl->debut ;
do
{
printf("%d",x);
p=p->suiv ;
}
while((p->suiv)!=NULL);
}
void main ()
{
clrscr();
/* apel fonction inserer*/
initialiser(adl);
do{
printf("entrer une valeur : ");
scanf("%d",&x);
inserer(adl,x);
printf("voulez vous inserer: ");
scanf("%s",&rep);
}
while(rep=='o');
/*affichage*/
affichage(adl);
getch();
}
non mais faut vraiment leur macher le travail a ces jeunes
http://www.presence-pc.com/forum/ppc/Programmation/Quel...
http://www.presence-pc.com/forum/ppc/Programmation/Quel...
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct tnoeud {
int ele ;
struct tnoeud *suiv ;
} Tnoeud ;
typedef struct {
Tnoeud *debut ;
Tnoeud *fin ;
int lg ;
}liste ;
liste *adl ;
int n,i,x,lg;
char rep ;
/*creer un noeud */
Tnoeud * creer_noeud (int x)
{
Tnoeud *p ;
p= (Tnoeud * )malloc (sizeof(Tnoeud));
if (p)
{
p->ele = x ;
p->suiv = NULL ;
}
return p ;
}
void initialiser (liste *adl)
{
adl->debut=NULL ;
adl->fin=NULL;
adl->lg = 0 ;
}
void inserer ( liste *adl , int x )
{
Tnoeud *p = creer_noeud(x);
if (p)
{
adl->debut = adl->fin = p ;
adl->lg+=1;}
else
{
adl->fin->suiv = p;
adl->fin = p ;
adl->lg+=1;
}
printf("la longeur est : %d \n",adl->lg);
}
void affichage(liste *adl)
{
Tnoeud *p ;
p=adl->debut ;
do{
printf("%d",x);
p=p->suiv ; }
while((p)!=NULL);
}
void main ()
{
clrscr();
/* apel fonction inserer*/
initialiser(adl);
do{
printf("entrer une valeur : ");
scanf("%d",&x);
inserer(adl,x);
printf("voulez vous inserer: ");
scanf("%s",&rep);
}
while(rep=='o');
/*affichage*/
affichage(adl);
getch();
}
nacerleroi11 a dit :
liste *adl ;
<...>
void main ()
{
/* apel fonction inserer*/
initialiser(adl);
<...>
Tu veux probablement (pas besoin de globale...)
<...>
int main (void)
{
liste adl ;
initialiser(&adl);
<...>
Citation :
char rep ;
void main ()
{
scanf("%s",&rep);
Horrible !
"%s" attend l'adresse du premier élément d'un tableau. Pour "o", il faut un tableau d'au moins 2 caractères : {'o', 0}
int main (void)
{
char rep[8] ;
scanf("%7s",rep);
Lassé par la pub ? Créez un compte
- Contenus similaires :
Tags :
- ForumCable hdmi probleme affichage
- ForumAfficher une liste chainee en java
- ForumAcer al1916w probleme affichage
- ForumProbleme affichage photo
- ForumProbleme affichage outlook
- ForumListe chainee en java
- ForumProbleme affichage secondaire
- ForumProbleme affichage mac
- ForumProbleme affichage javascript
- ForumProbleme affichage dvi
- Voir plus