Write down a module to merge two linked lists, Data Structure & Algorithms

Two linked lists are having information of the same type in ascending order. Write down a module to merge them to a single linked list that is sorted

merge(struct node *p, struct node *q, struct **s)

{

struct node *z;

z = NULL;

if((x= =NULL) && (y = =NULL))

return;

while(x!=NULL && y!=NULL)

{

if(*s= =NULL)

{

*s=(struct link *)malloc(sizeof(struct node *z));

z=*s;

}

else

{

z-->link=(struct link *)malloc(sizeof(struct node *));

z=z-->link;

}

if(x-->data < y-->data)

{

z-->data=x-->data;

x=x-->link;

}

else if(x-->exp > y-->exp)

{

z-->data=y-->data;

y=y-->link;

}

else if(x-->data= =y-->data)

{

z-->data=y-->data;

x=x-->link;

y=y-->link;

}

}

while(x!=NULL)

{

z   link = struct link *malloc(sizeof(struct node *));

z=z   link;

z-->data=x-->data;

x=x-->link;

}

while(y!=NULL)

{

z   link = struct link *malloc(sizeof(struct node *));

z=z   link;

z-->data=y-->data;

y=y-->link;

}

z-->link=NULL;

}

Posted Date: 7/9/2012 10:14:30 PM | Location : United States







Related Discussions:- Write down a module to merge two linked lists, Assignment Help, Ask Question on Write down a module to merge two linked lists, Get Answer, Expert's Help, Write down a module to merge two linked lists Discussions

Write discussion on Write down a module to merge two linked lists
Your posts are moderated
Related Questions
What is complexity of an algorithm? What is the basic relation between the time and space complexities of an algorithm? Justify your answer by giving an example.

write an algorithm and draw a flowchart to calculate the perimeter and area of a circle


Q. The reason bubble sort algorithm is inefficient is that it continues execution even after an array is sorted by performing unnecessary comparisons. Therefore, the number of comp

Determine the Components of Illumination The light reaching the eye when looking at a surface has clearly come from a source (or sources) of illumination and bounced off the su

Find a minimum cost spanning arborescence rooted at r for the digraph shown below, using the final algorithm shown in class. Please show your work, and also give a final diagram wh

A database is a collection of data organized in a manner that facilitates updation, retrieval and management of the data. Searching an unindexed database having n keys will have a

The complexity of multiplying two matrices of order m*n and n*p is    mnp

I need help writing a pseudocode for my assignment can anyone help?

Ask question #Minimum 10000 words accepted#