Tweet
#include <stdio.h>
#include <malloc.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 ) ;
display ( p ) ;
}
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 ) ;
}
void display ( struct node *q )
{
printf ( "\n" ) ;
while ( q != NULL )
{
printf ( "%d ", q -> data ) ;
q = q -> link ;
}
}
Insertion at the end of a linked list using recursion in C Programming
Posted by
LAHAUL SETH
~
Insertion at the end of a linked list using recursion in C Programming
2012-02-20T17:57:00+05:30
LAHAUL SETH
Linked List in C
|
Programming in C
|
Comments
Insertion at the end of a linked list using recursion in C Programming
2012-02-20T17:57:00+05:30
LAHAUL SETH
Linked List in C
|
Programming in C
|