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
Explain the bubble sort algorithm. Answer This algorithm is used for sorting a list. It makes use of a temporary variable for swapping. It compares two numbers at an insta

Explain an efficient and effective way of storing two symmetric matrices of the same order in the memory. A n-square matrix array will be symmetric if a[j][k]=a[k][j] for all j

Question 1 Describe the following- Well known Sorting Algorithms Divide and Conquer Techniques Question 2 Describe in your own words the different asymptotic func

Program will demonstrate deletion of an element from the linear array /* declaration of delete_list function */ voiddelete_list(list *, int); /* definition of delete_list

There are four data type groups:  Integer kepts whole numbers and signed numbers Floating-point Stores real numbers (fractional values). Perfect for storing bank deposit

Question 1. Explain the different types of traversal on binary tree 2. Explain the Prim's minimum spanning tree algorithm 3. Differentiate fixed and variable storage allo

Ask queConsider the following functional dependencies: Applicant_ID -> Applicant_Name Applicant_ID -> Applicant_Address Position_ID -> Positoin_Title Position_ID -> Date_Position_O

Problem 1. You are asked to store Names of all 100 students of class A in your Learning Centre. Which data type will you use? What is its syntax? Explaining the data typ

AVL trees are applied into the given situations: There are few insertion & deletion operations Short search time is required Input data is sorted or nearly sorted

Define the External Path Length The External Path Length E of an extended binary tree is explained as the sum of the lengths of the paths - taken over all external nodes- from