Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
You are given the following method signature:

C#
public static int[] MergeAndReorder(int[] a, int[] b) { }


Arrays a and b are both already sorted in ascending order.
How can we return the union of all elements in a and b, sorted in descending order.
You may not use any native sorting functionality of C#, such as SortedList or .OrderBy().
Your variables may only be primitives (and obviously an integer array for the result).

Any one good in programming can do this
Posted
Updated 16-Aug-12 18:13pm
v3
Comments
BillW33 16-Aug-12 9:04am    
This sounds like a homework assignment. We are not here to do your homework for you.
[no name] 16-Aug-12 9:12am    
"Your task ".. enough said.
bbirajdar 16-Aug-12 9:32am    
I am not prepared for this task.. :)

This is not a site for homework assignments. If you aren't interested in programming you probably choose the wrong study.

Good luck!
 
Share this answer
 
Comments
Prasad_Kulkarni 17-Aug-12 0:32am    
Exactly. A +5
This[^] would help you. (To be more precise, do read the 7th point.)
 
Share this answer
 
v2
No code, just how I would do the algorithm:

Create a new target integer array. Size should be the added sizes of a and b.

You need three indexes: for a, b and target. The trick to invert sorting direction is to start a and b indexes at their last elements and iterate backwards.

Iterate over the new array. Each element is either copied from a or b, whichever is smaller (in value, not index). The one that copied its value also makes its index move on.

Remember not to use indexes smaller than zero.

Happy coding.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900