adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C to display data of singly linked list in reverse order using recursive function.

Program in C to display data of singly linked list in reverse order using recursive function.



  • Create singly linked list 
  • Insert data using general function
  • Display data of singly linked list using recursive function
  • Display data of singly linked list in reverse order using recursive 

#include<stdio.h>
#include<stdlib.h>
 struct Node{
    int data;
    struct Node *next;
  };
  typedef struct Node Node;
  void insert(Node **b, int);
  void show(Node **b);
  void reverse(Node **b);
  int main()
   {
       Node *start = NULL;
       insert(&start,34);
       insert(&start,64);
       insert(&start,4);
       insert(&start,45);
       insert(&start,15);
       insert(&start,88);
       printf("Elements of linked list is ");
       show(&start);
       printf("\nElements of linked list in reverse order ");
       reverse(&start);
       return 0;
   }
   void insert(Node **b, int data)
    {
     Node *temp, *newN;
     newN = malloc(sizeof(Node));
     newN->data = data;
     newN->next = NULL;
     if(*b == NULL)
        *b = newN;
     else{
        temp = *b;
        while(temp->next != NULL)
            temp = temp->next;
        temp->next = newN;
      }
    }
   void show(Node **b){
      Node *temp = *b;
      if(temp == NULL)
        return;
      printf("%d  ",temp->data);
      show(&temp->next);
   }
   void reverse(Node **b){
      Node *temp = *b;
      if(temp == NULL)
        return;
      reverse(&temp->next);
      printf("%d  ",temp->data);
   }
Output :-




Related Programs
Oueue Programs 

Post a Comment

0 Comments