Algorithm to merge the lists together, Data Structure & Algorithms

Assignment Help:

Q. Let X = (X1, X2, X3,....Xn) and Y= (Y1, Y2, Y3,....Xm) be the two linked lists respectively. Write down an algorithm to merge the lists together to get the linked list Z such that

Z =  (X1, Y1, X2, Y2,....Xm, Ym,Xm+1....Xn) if m<=n or

Z = (X1, Y1,X2,Y2....Xn,Yn,Yn+1....Ym) if m>n.                                               

Ans.

void near (*head1,*head2,*head3)

{

p1 = head1;

p2 = head2;

p3 = head3;

if (p1 != NULL)

{

p3 = head3 = p1 ;

p1=p1     next ;

}

while (p1!= NULL && p2 != NULL)

{

p3      next = p2 ; p2=p2         next; p3=p3               next;

p3     next = p1; p1 = p1  next ; p3 = p3    next ;

}

for ( ; p1 != NULL; p1 = p1 ?  next)

{

p3      next = p1;

p3 = p3       next ;

}

for ( ; p2 != NULL ; p2 = p2 ?  next)

{

P2       next = p2 ;

p2 = p2   next ;

}


Related Discussions:- Algorithm to merge the lists together

Algorithm for stack using array, write an algorithm for stack using array p...

write an algorithm for stack using array performing the operations as insertion ,deletion , display,isempty,isfull.

Binary search tree, A binary search tree (BST), which may sometimes also be...

A binary search tree (BST), which may sometimes also be named a sorted or ordered binary tree, is an edge based binary tree data structure which has the following functionalities:

Algorithm to merge the lists together, Q. Let X = (X1, X2, X3,....Xn) and Y...

Q. Let X = (X1, X2, X3,....Xn) and Y= (Y1, Y2, Y3,....Xm) be the two linked lists respectively. Write down an algorithm to merge the lists together to get the linked list Z such th

Areas of use - sequential files, Sequential files are most frequently utili...

Sequential files are most frequently utilized in commercial batch oriented data processing where there is the concept of a master file on which details are inserted periodically. F

Write a program for linear search, In the book the following methods are pr...

In the book the following methods are presented: static void selectionSort(Comparable[] list) static void insertionSort(Comparable[] list) static boolean linearSearch(Comparable

Degree of node, Q. The degree of a node is defined as the number of childre...

Q. The degree of a node is defined as the number of children it has. Shear show that in any binary tree, the total number of leaves is one more than the number of nodes of degree 2

Tree, tree is graph or not

tree is graph or not

Define big omega notation, Define Big Omega notation Big Omega notatio...

Define Big Omega notation Big Omega notation (?) : The lower bound for the function 'f' is given by the big omega notation (?). Considering 'g' to be a function from the non-n

Asymptotic analysis, Asymptotic Analysis Asymptotic analysis is dependi...

Asymptotic Analysis Asymptotic analysis is depending on the idea that as the problem size grows, the complexity can be defined as a simple proportionality to some known functio

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd