For this assignment, you must develop a program which will merge the contents of two lists, removing duplicates.

You must:

• develop the pseudocode
• desk-check
• test the program to ensure that it works for appropriate sets of data

Your list merge program should be a simple program which accepts whole number data for two lists which is entered by the user, and merges the two lists removing all duplicates.

Your program must take in the following inputs from the user:

• The number of values to be entered into each list (the array size).
• Each value to be stored in the arrays. Each list must not contain any duplicate numbers, so this must be checked for and prevented when adding to a list. However, a number which appears on the first list can still be added to the second list.

The two lists can be of different lengths, but cannot contain more than 50 elements. The program should work for whole numbers and should be able to handle a range of numbers from 0 to 50000. The program must check that the values entered fall within the valid ranges.

Merging two lists to remove duplicates is a multi-step process which involves searching over both arrays and adding the contents which appear in both arrays into an array to store the duplicates (in set theory, this is known as the Intersection). You should only place one copy of each duplicate number in this array. The numbers which only appear in one of the arrays but not both should be added to a separate new array. Finally, a new array should be created which is the merged list of both arrays: this list contains all the numbers from both lists with no duplicates.

Working through an example should help clarify this

We have two data sets of 10 numbers and want to find the duplicates and create a merged list. The data sets are below.

List A: 3, 4, 15, 27, 36, 76, 24, 35, 16, 51
List B: 7, 24, 19, 64, 121, 51, 12, 9, 15, 94

Looking at both lists, we can see that there are numbers which appear in both lists. If we step over List A and compare each number in turn to every number on List B, the first duplicate we find is 15, which is highlighted below:

List A: 3, 4, 15, 27, 36, 76, 24, 35, 16, 51
List B: 7, 24, 19, 64, 121, 51, 12, 9, 15, 94

The next duplicate number we find is 24:

List A: 3, 4, 15, 27, 36, 76, 24, 35, 16, 51
List B: 7, 24, 19, 64, 121, 51, 12, 9, 15, 94

The final duplicate number we find is 51:

List A: 3, 4, 15, 27, 36, 76, 24, 35, 16, 51
List B: 7, 24, 19, 64, 121, 51, 12, 9, 15, 94

We therefore add 15, 24, and 51 to the Intersection list.
The numbers that only appear on List A OR List B but not both get added to the ‘A OR B’ List.

The next step is to create the merged list. This is the combination of the Intersection List and the A OR B List.

Your program will need to perform the following operations:

• Accept user input for List A size and List B size, and values
• Perform data validation on user input
• Inform the user if any of the data is invalid.
• Prompt the user to re-enter the input while it is not valid
• Identify the duplicate numbers and add them to an Intersection list
• Identify the non-duplicate numbers and add them to an A OR B list
• Create a merged list
• Output the results

Good exercise! Get started, and then we may help you. We don't do your homework for you. Think about the problem. Your professor has already broken the work down into manageable chunks. Look at each first in isolation, and then as a gestalt of all the parts. Thats how real software works. :-)

This article has been dead for over six months. Start a new discussion instead.