Quantcast
Channel: C - Codecademy Forums
Viewing all articles
Browse latest Browse all 25

Inverted linked list In C

$
0
0

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 :+1:

#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

Read full topic


Viewing all articles
Browse latest Browse all 25

Trending Articles