> ... It doesn't like my temporary array c and I can't get anything to sort ...
the compiler should not like it at all (it is not c++); and should give you an error.
int c[size]; //array c - the temporary array for sorting
size is not a constant known at compile time.
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
The size variable is a variable. The compiler does not know what value it might hold at any given time.
Since you are using C++, you should be using a vector or deque for this instead of an array. But if you must use an array, just make one as big as the largest size you think you'll have, and make sure that it complains if size ever gets too large.
I haven't time to look very deeply at your code ATM, so if you are still having problems later I'll help then.
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
I think you need to go sit down with your professor and work on this a little with him. There are a lot of syntactic and logical errors in here, which I think you can best overcome by working with someone face to face. He shouldn't give you a hard time. Most professors are genuinely pleased when students ask for help understanding a problem. (If for no other reason, it gives them a chance to talk about it more.)
Before you go, google "merge sort" to find some good animations of what is going on. Ignore the stuff in the WikiPedia. (There's nothing wrong with it, it'll just confuse you and your professor will know if you scavenge code from it --honestly, it would be really obvious.)
I was going to give you a bunch of stuff about a binary tree (which is a form of linked list) but I think you ought to go see your professor first. Most merge sorts are done using recursion instead of using an actual binary tree in memory --which is how you are trying to do it.
Hope this helps.
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229