Spread the post

Single linked list check identical linked lists

Given a two linked list L1 and L2. Our goal is to identified given linked list are identical or not.

Following condition of identical linked list1) Number of node are same

2) Node data are equal/p>

Example Accepted Output

Case One

Given list is :

Linked list one

12-->44-->64-->91-->44-->33-->13-->44--->NULL

Linked list two

12-->44-->64-->91-->44-->33-->13-->44--->NULL

Result :

Identical of linked list

Case two

Given list is :

Linked list one

12-->44-->64-->91-->44-->33-->13-->44--->NULL

Linked list two

12-->44-->64-->91-->44-->33-->13-->44--->32--->NULL

Result :

Not Identical of linked list

C program for Check two Linked Lists are Identical or not

Titile of code
 
-------Case One-------


First linked list data : 
15  51  63  21  52  51  51  23  
Second linked list data : 
15  51  63  21  52  51  51  23  

  Linked list is equal (identical) 


 Free linked list One
 Free linked list Node element 
 Free linked list Two
 Free linked list Node element 


-------Case Two-------


First linked list data : 
65  22  63  44  52  51  51  23  
Second linked list data : 
65  22  63  44  52  51  51  23  42  

 This linked list not equal (identical) 


 Free linked list One
 Free linked list Node element 
 Free linked list Two
 Free linked list Node element  

Try it yourself

Check identical of linked list using recursion

Function to check identical linked list

Time complexity of this program O(n)

C program to check identical of two linked list using recursion.


OutPut


Stack Areamainresult (int) ? root1(pointer)root2(pointer) Heap Areastruct Nodedata (int)= 15next (pointer) struct Nodedata (int)= 51next (pointer) struct Nodedata (int)= 63next (pointer) struct Nodedata (int)= 21next (pointer) struct Nodedata (int)= 52next (pointer) struct Nodedata (int)= 51next (pointer) struct Nodedata (int)= 51next (pointer) struct Nodedata (int)= 23next (pointer)= NULLstruct Nodedata (int)= 15next (pointer) struct Nodedata (int)= 51next (pointer) struct Nodedata (int)= 63next (pointer) struct Nodedata (int)= 21next (pointer) struct Nodedata (int)= 52next (pointer) struct Nodedata (int)= 51next (pointer) struct Nodedata (int)= 51next (pointer) struct Nodedata (int)= 23next (pointer)= NULL

Try it yourself

Spread the post

Recommended Posts: