Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Inverted linked list in C

Inverted linked list in C

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelp
3 Posts 3 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Amine Saber
    wrote on last edited by
    #1

    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 #include 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

    L D 2 Replies Last reply
    0
    • A Amine Saber

      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 #include 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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      There are two issues: 1. Where you create the cellule structures:

      for(i=0;isuivant = NULL; // Mark the last entry as having no follower
      

      2. Your recursive method

      void affichage (struct cellule *liste){
      if (liste ==NULL) // this just needs to check for the end of the list
      {
      return; // no more entries
      }
      affichage(liste->suivant); // process the next entry in the list
      printf(" %d ",liste->a); // on return print the current entry's value
      }

      1 Reply Last reply
      0
      • A Amine Saber

        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 #include 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

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        By "inverted" do you mean you want to print your list in reverse order? E.g. input: 1 2 3 4 5 output: 5 4 3 2 1

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups