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
Operation of Algorithm The following sequence of diagrams shows the operation of Dijkstra's Algorithm. The bold vertices show the vertex to which shortest path has been find ou

Write a recursive function the computes the number of digits in a positive integer n. For example if n = 6598, the function should return 4. Find a variant expression and a thresho

What are the properties of an algorithsm?

Define the term 'complexity of an algorithm; Complexity of an algorithm is the calculate of analysis of algorithm. Analyzing an algorithm means predicting the resources that th

include include include /* Definition of structure node */ typedef struct node { int data; struct node *next; } ; /* Definition of push function */

This is a k-ary position tree wherein all levels are filled from left to right. There are a number of specialized trees. They are binary trees, AVL-trees, binary search trees, 2

explain working of siso-register to store 1011 and show timing diagram &table

This question deals with AVL trees. You must use mutable pairs/lists to implement this data structure: (a) Define a procedure called make-avl-tree which makes an AVL tree with o

Instructions Design and test a reference array. Reference array stores the references to user supplied objects of different types. Just think it as a heterogeneous array wh

Question 1 . Give the structure of PL/SQL Blocks and explain Question 2 . Differentiate between PL/SQL functions and procedures Question 3 . Explain the following Par