Problem:

For the OrdArray class in the orderedArray.java program (Listing 2.4 on page 59), you are asked to add the following methods

  • A merge() method so you can merge two ordered source arrays into an ordered destination array. To simplify, for duplicate values (no mater in an array or two arrays), only count once.
  • A common() method so you can get the common values owned by the two ordered source arrays into an ordered destination array. For duplicate values, only count once.
  • Using the objected oriented analysis and design, using the available insert(), find(). delete() and display() methods.
  • You cannot use any available library.

Write code in main() of class OrderedApp that inserts some random numbers into the two source arrays, invokes merge() and common() and displays the contents of the resulting arrays. The source arrays may hold different numbers of data items. In your algorithm you will need to compare the keys of the source arrays, picking the smallest one to copy to the destination. You'll also need to handle the situation when one source array exhausts its contents before the other.

Example:

Source array A = {3, 6, 8, 8, 11, 17, 25, 34, 38, 46, 48, 48, 48, 57, 62, 69, 72, 72, 77, 83};

Source array B = {5, 8, 14, 25, 31, 37, 41, 48, 48, 52, 77, 82, 94};

Then, Destination array C (after merge) = {3, 5, 6, 8, 11, 14, 17, 25, 31, 34, 37, 38, 41, 46, 48, 52, 57, 62, 69, 72, 77, 82, 83, 94};

Destination array D (after common) = {8, 25, 48, 77};

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.