Algorithm to merge the lists together, Data Structure & Algorithms

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 ;

}

Posted Date: 7/13/2012 2:39:10 AM | Location : United States







Related Discussions:- Algorithm to merge the lists together, Assignment Help, Ask Question on Algorithm to merge the lists together, Get Answer, Expert's Help, Algorithm to merge the lists together Discussions

Write discussion on Algorithm to merge the lists together
Your posts are moderated
Related Questions
what are grounded header linked lists?

Write a program for reversing the Linked list

This unit discussed about data structure called Arrays. The easiest form of array is a one-dimensional array which may be described as a finite ordered set of homogeneous elements

Channel access In first generation systems, every cell supports a number of channels. At any given time a channel is allocated to only one user. Second generation systems also

Q. Give the adjacency matrix for the graph drawn below:                                                 Ans: Adjacency matrix for the graph given to us

Explain Optimal Binary Search Trees One of the principal application of Binary Search Tree is to execute the operation of searching. If probabilities of searching for elements

I was wanting to know where this web site was created. My second question is,,, are the online tuters accredited teachers? If they are, are they only working for the website or ma

Q. Establish the usage of linked lists for polynomial manipulation.                                       Ans. Usag e of Linked List for Polynomial Manipulation. Link

Step 1: Choose a vertex in the graph and make it the source vertex & mark it visited. Step 2: Determine a vertex which is adjacent to the source vertex and begun a new search if

State the example of pre- and post-conditions Suppose that function f(x) should have a non-zero argument and return a positive value. We can document these pre- and post-condit