Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Data File StructureRSS Feeds

Program to add a new node at the end of linked list using recursion

Posted By: Riley Evans     Category: C Programming     Views: 12058

Program to add a new node at the end of linked list using recursion.

Code for Program to add a new node at the end of linked list using recursion in C Programming

#include <stdio.h>
#include <conio.h>
#include <alloc.h>

struct node
{
    int data ;
    struct node *link ;
} ;

void addatend ( struct node **, int ) ;
void display ( struct node * ) ;

void main( )
{
    struct node *p ;

    p = NULL ;

    addatend ( &p, 1 ) ;
    addatend ( &p, 2 ) ;
    addatend ( &p, 3 ) ;
    addatend ( &p, 4 ) ;
    addatend ( &p, 5 ) ;
    addatend ( &p, 6 ) ;
    addatend ( &p, 10 ) ;

    clrscr( ) ;
    display ( p ) ;
}

/* adds a new node at the end of the linked list */
void addatend ( struct node **s, int num ) { if ( *s == NULL ) { *s = malloc ( sizeof ( struct node ) ) ; ( *s ) -> data = num ; ( *s ) -> link = NULL ; } else addatend ( &( ( *s ) -> link ), num ) ; } /* displays the contents of the linked list */
void display ( struct node *q ) { printf ( "\n" ) ; /* traverse the entire linked list */
while ( q != NULL ) { printf ( "%d ", q -> data ) ; q = q -> link ; } }
  
Share: 



Riley Evans
Riley Evans author of Program to add a new node at the end of linked list using recursion is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!