Join Our Email Alerts-Subscribe
Important Note:Login & Check Your Email Inbox and Activate Confirmation Link



Enter Your Email :

Copyright Disclaimer:
Section 107 of the Copyright Act Fair Use Contents .
We are forwarding content link(s) from our website to content website & We are not serving any contents.
Main Source:Google.com.All the Content PDF link(s) is/are obtained from GoogleSearch
for the purpose of Education & Teaching Intention. Not for commercial purpose.
Technicalsymposium.com is not liable/responsible for any copyright issues.

Data Structure Programming Source Codes & Study Notes-Free Download


DataStructure-Program to compare two linked lists using recursion.

#include <stdio.h>
#include <conio.h>
#include <alloc.h>
struct node
{
int data ;
struct node *link ;
} ;
void append ( struct node **, int ) ;
int compare ( struct node *, struct node * ) ;
void main( )
{
struct node *first, *second ;
first = second = NULL ; /* empty linked lists */
append ( &first, 1 ) ;
append ( &first, 2 ) ;
append ( &first, 3 ) ;
append ( &second, 1 ) ;
append ( &second, 2 ) ;
append ( &second, 3 ) ;
clrscr( ) ;
if ( compare ( first, second ) )
printf ( "Both linked lists are EQUAL" ) ;
else
printf ( "Linked lists are DIFFERENT" ) ;
}
/* adds a node at the end of a linked list */
void append ( struct node **q, int num )
{
struct node *temp ;
temp = *q ;
if ( *q == NULL ) /* if the list is empty, create first node */
{
*q = malloc ( sizeof ( struct node ) ) ;
temp = *q ;
}
else
{
/* go to last node */
while ( temp -> link != NULL )
temp = temp -> link ;
/* add node at the end */
temp -> link = malloc ( sizeof ( struct node ) ) ;
temp = temp -> link ;
}
/* assign data to the last node */
temp -> data = num ;
temp -> link = NULL ;
}
/* compares 2 linked lists and returns 1 if linked lists are equal and 0 if unequal */
int compare ( struct node *q, struct node *r )
{
static int flag ;
if ( ( q == NULL ) && ( r == NULL ) )
flag = 1 ;
else
{
if ( q == NULL || r == NULL )
flag = 0 ;
if ( q -> data != r -> data )
flag = 0 ;
else
compare ( q -> link, r -> link ) ;
}
return ( flag ) ;
}

 

Programming & Lab Manuals- ebooks & Codes PDF


Software Programming Study Materials PDF-Free Download



Technicalsymposium.com-All Study Materials PDF-Free Download







Technicalsymposium.com-Free Live Support-Chat with Our Experts

Official Contact: +91-9245556793 (Whatsapp Message / SMS / Voice Call)


Our Expert team is ready to answer all your questions immediately-Feel free to speak in Tamil/English.

(Example:Events info/Lecture Notes/Off-Campus & All Jobs/Projects & All education information)

Working hrs (IST): (Morning: 10:00AM-3:00 PM) and (Evening:5:00 PM to 10:00 PM)

All Latest Question & Answer Page (FAQ)-Click here