Hello friends ! , in my following code in C I want to invert my linked list in the display using a 𝗿𝗲𝗰𝘂𝗿𝘀𝗶𝘃𝗲 𝗳u𝗻𝗰𝘁𝗶𝗼𝗻 ; but the code does not work !! Is there an error; thank you for mentioning it
#include<stdio.h>
#include<stdlib.h>
struct cellule{
int a;
struct cellule *suivant;
};
//Recursive function to display the list in invers order
void affichage (struct cellule *liste){
while (liste!=NULL){
affichage(liste->suivant);
printf(" %d “,liste->a);
}
}
int main()
{
struct cellule *liste,*p,*q,*r;
int n,i;
printf(“Donner le nombre d’elements de la liste:\n”);
scanf(”%d",&n);
printf(“Entrer les elements de la liste:\n”);
for(i=0;i<n;i++)
{
p=(struct cellule *)malloc(sizeof(struct cellule));
scanf(“%d”,&(*p).a);
if(i==0) liste = p;
else (*q).suivant=p;
q=p;
}
affichage(liste);
printf(“\n”);
system(“pause”);
return 0;
}
1 post - 1 participant