answersLogoWhite

0

If you mean merging two sorted list, that would be like this:

to= empty

WHILE NOT empty(a) OR NOT empty(b) DO

IF empty(b) OR first(a)<first(b) THEN

append(to, first(a))

a:= next(a)

ELSE IF empty (a) OR first(a)>first(b) THEN

append(to, first(b))

b:= next(b)

ELSE IF first(a)=first(b) THEN

append(to, first(a))

append(to, first(b)) # if you want duplicates in the output

a:= next(a)

b:= next(b)

END IF

END WHILE

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

Is there a c program to multiply two polynomials using linked lists?

yes


How can you efficiently sort a doubly linked list?

To efficiently sort a doubly linked list, you can use a sorting algorithm such as merge sort or quicksort. These algorithms can be implemented to work with doubly linked lists by considering the pointers in both directions. By recursively dividing the list and merging or partitioning the elements, you can achieve an efficient sorting process.


What advantages of a sorted list over a linked list?

All lists are linked lists; there is no such thing as a separate "sorted list". There are algorithms that can sort a list, of course, but they all work on linked lists.


What is binary linked list?

There is no such thing. There are binary trees and linked lists.


What is the use of merging while sorting?

Merging data when sorting (which occurs with mergesort, quicksort, and others) is based on the idea that merging two sorted lists is faster than merging two unsorted lists. This makes sense - it will take less comparisons to merge {1 3 5} and {2 4 6} than {3 1 5} and {6 4 2}.


How can we represent polynomials using linked lists?

30


what are the various operations in linked list which can be performed on linked list?

In linked list, there are various operations in linked list that you can perform on linked list, eg: adding new elements, deleting elements, getting the first element, getting the next element after an element, any many others.


What is a MET?

The website linked below lists 49 different meanings for MET.


What is an efficient algorithm to merge k sorted lists in O(n log k) time complexity?

One efficient algorithm to merge k sorted lists in O(n log k) time complexity is the &quot;Merge with Divide and Conquer&quot; approach. This algorithm involves recursively dividing the k lists into two halves, merging them individually, and then merging the resulting halves until all lists are merged. This approach ensures a time complexity of O(n log k) by utilizing the divide and conquer strategy to efficiently merge the sorted lists.


What is a linked list used for?

A linked list is used in computer science to store data as a series of related nodes. Linked lists are used as the basis for abstract data types when programming. The chief advantage of a linked list is that data can be added or removed from the list without having to reorganize the whole list. A drawback to linked lists can be that it is difficult to sort, organize, or recall specific information from the list.


What is the quick sort program using linked list and recursive methods?

Linked lists are not ideally suited to the quicksort algorithm because linked lists do not provide constant-time random access. The most efficient means of implementing quicksort upon a list is to move all the elements to an array, sort the array using quicksort, then move the elements back into a list. This increases the complexity by O(n*2), which is costly, but is more than compensated for by the improved efficiency of sorting an array.


How do you write a c program to calculate factorial using recursion?

unsigned long nfact(int n) if (n==2) return n else return n*nfact(n-1); For 32-bit integers, this program will fail at N==13, due to overflow. For 64-bit integers, it will fail at N==21. A solution for this is an arbitrary decimal arithmetic library, perhaps based on linked lists.