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

Assignment Help:

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;

}


Related Discussions:- Write down a module to merge two linked lists

Advantage of list over arrays, The advantage of list over Arrays is flexibi...

The advantage of list over Arrays is flexibility. Over flood is not a problem until the computer memory is bushed. When the individual record are quite large, it may be difficult t

State warnock algorithm, Warnock's Algorithm An interesting approach to...

Warnock's Algorithm An interesting approach to the hidden-surface problem was presented by Warnock. His method does not try to decide exactly what is happening in the scene but

Abstract Data Types, A useful tool which is used for specifying the logical...

A useful tool which is used for specifying the logical properties of a data type is called the abstract data type or ADT. The term "abstract data type" refers to the fundamental ma

Differentiate between nonpersistent and 1-persistent, Differentiate between...

Differentiate between Nonpersistent and 1-persistent Nonpersistent: If the medium is idle, transmit; if the medium is busy, wait an amount of time drawn from a probability dist

Dijkstra's algorithm, Q. Explain Dijkstra's algorithm for finding the short...

Q. Explain Dijkstra's algorithm for finding the shortest path in the graph given to us.  Ans: The Dijkstra's algorithm: This is a problem which is concerned with finding

State about the pre- and post conditions, State about the pre- and post con...

State about the pre- and post conditions Programmers can easily document other pre- and post conditions and class invariants, though, and insert code to check most value preco

String pattern matching, Document processing is quickly becoming one of the...

Document processing is quickly becoming one of the dominant functions of computers. Computers are utilized to edit, search & transport documents over the Internet, and to display d

Define graph, A graph is a mathematical structure giving of a set of vertex...

A graph is a mathematical structure giving of a set of vertexes (v1, v2, v3) and a group of edges (e1, e2, e3). An edge is a set of vertexes. The two vertexes are named the edge en

Physical database design and sql queries, In this part, students are allowe...

In this part, students are allowed to implement the following simplifications in their table and data design. o Availability for the beauty therapists don't have to be considere

Algorithm for dfs, Step 1: Choose a vertex in the graph and make it the sou...

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

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