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

LINKED LIST, HOW LINKED LIST HEADER WORKS? HOW TO INSERT AND DELETE ELEMENT...

HOW LINKED LIST HEADER WORKS? HOW TO INSERT AND DELETE ELEMENTS IN LINKED LIST?

Draws a rectangular grid algorithms, Prepare a GUI called Hotplate GUI that...

Prepare a GUI called Hotplate GUI that holds a central panel that draws a rectangular grid that represents Element objects which should be held in a 2-dimensional array. The applic

Calculate the k-th power and recursive algorithem, 1. The following is a r...

1. The following is a recursive algorithm to calculate the k -th power of 2. Input k a natural number Output kth power of 2 Algorithem: If k =0then return 1 Else return 2* po

Algorithm, Example of worse case of time

Example of worse case of time

Illustrate the operations of the symbol abstract data type, The operations ...

The operations of the Symbol ADT The operations of the Symbol ADT are the following. a==b-returns true if and only if symbols a and bare identical. a symbol bin Unico

Selection sort, how to reduce the number of passes in selection sort

how to reduce the number of passes in selection sort

Abstract data type- queue, A significant aspect of Abstract Data Types is t...

A significant aspect of Abstract Data Types is that they explain the properties of a data structure without specifying the details of its implementation. The properties might be im

Size of stack, The size of stack was declared as ten. Thus, stack cannot ho...

The size of stack was declared as ten. Thus, stack cannot hold more than ten elements. The major operations which can be performed onto a stack are push and pop. However, in a prog

Define abstract data type & column major ordering for arrays, Q1. Define th...

Q1. Define the following terms: (i) Abstract data type. (ii) Column major ordering for arrays. (iii)  Row major ordering for arrays. Q2. Explain the following: (i) A

Define different types of sparse matrix, Q1. Define a sparse matrix. Explai...

Q1. Define a sparse matrix. Explain different types of sparse matrices? Evaluate the method to calculate address of any element a jk of a matrix stored in memory. Q2. A linear

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