944,113 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 696
  • C RSS
Nov 6th, 2009
0

Merge sort or an alternative..

Expand Post »
Hi there guys,

So I have two arrays, and each arrays got 5 elements (integers). My goal is to to arrange the elements of each of those arrays in a descending order and save them in a new array.

I started off with bubble sorting each of those arrays and rearranging the elements in a descending sequence. It just seemed reasonable to start with that.

However now, I have to merge those two arrays. I thought it'd be wise to create a new empty array with a size big enough to contain all the elements, but I can't figure out for the life me how to arrange them in a descending order while merging them.

I know I could just transfer all the elements to the new array and then bubble sort it but that seems tedious. Any ideas?

Thanks in advance.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
s.p.i. is offline Offline
4 posts
since Nov 2009
Nov 6th, 2009
0
Re: Merge sort or an alternative..
In my opinion, creating merging the arrays and then sorting the merged array isn't a bad idea because it's simple. But that depends on what you seek - performance or simplicity. Everything is possible to code but depends on your experience and the amount of time to spend doing it.

By the way, I doubt sorting and merging at the same time would be a lot faster than merging and then sorting.

That's just my opinion - accept it or not.

edit: Separated merging could save you some lines of code when implementing other sorting algorithms.
Last edited by venomxxl; Nov 6th, 2009 at 1:47 pm.
Reputation Points: 34
Solved Threads: 7
Junior Poster in Training
venomxxl is offline Offline
72 posts
since Jan 2009
Nov 6th, 2009
0
Re: Merge sort or an alternative..
Click to Expand / Collapse  Quote originally posted by venomxxl ...
In my opinion, creating merging the arrays and then sorting the merged array isn't a bad idea because it's simple.
I agree, I implemented the aforementioned idea and its working just fine but I am always open to learning new stuff.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
s.p.i. is offline Offline
4 posts
since Nov 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Reading from the Command line
Next Thread in C Forum Timeline: Message Queue Error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC