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
Define Big Theta notation Big Theta notation (θ) : The upper and lower bound for the function 'f' is given by the big oh notation (θ). Considering 'g' to be a function from t

Q. Write down an algorithm to insert a node in the beginning of the linked list.                         Ans: /* structure containing a link part and link part

An undirected graph G with n vertices and e edges is shown by adjacency list.  What is the time required to generate all the connected components? O (e+n)

(1) Sort a list of distinct numbers in ascending order, using the following divide- and-conquer strategy (Quicksort): divide the list of numbers into two lists: one that contains a

Let us assume a file of 5 records that means n = 5 And k is a sorted array of keys of those 5 records. Let key = 55, low = 0, high = 4 Iteration 1: mid = (0+4)/2 = 2

Explain about greedy technique The  greedy  method  suggests  constructing  a   solution  to  an  optimization  problem   by  a sequence of steps, every expanding a partially c

Decision Tree A decision tree is a diagram that shows conditions and actions sequentially and therefore shows which condition is to be considered first, second and so on. It is

Two-dimensional array is shown in memory in following two ways:  1.  Row major representation: To achieve this linear representation, the first row of the array is stored in th

Compare zero-address, one-address, two-address, and three-address machines by writing programs to compute: Y = (A – B X C) / (D + E X F) for each of the four machines. The inst

The  total  of  time  needed  by  an algorithm to run to its completion is termed as time complexity. The asymptotic running time of an algorithm is given in terms of functions. Th