Data Structures and Algorithms with Object-Oriented Design Patterns in C#
next up previous contents index

Union

The union operation for MultisetAsLinkedList class requires the merging of two ordered, linked lists as shown in Program gif. We have assumed that the smallest element contained in a multiset is found at the head of the linked list and the largest is at the tail.

   program28022
Program: MultisetAsLinkedList class Union method.

The Union method computes its result as follows: The main loop of the program (lines 14-26) traverses the linked lists of the two operands, in each iteration appending the smallest remaining element to the result. Once one of the lists has been exhausted, the remaining elements in the other list are simply appended to the result (lines 27-30). The total running time for the Union method is O(m+n), where tex2html_wrap_inline66721 and tex2html_wrap_inline66723.


next up previous contents index

Bruno Copyright © 2001 by Bruno R. Preiss, P.Eng. All rights reserved.