Hot answers tagged

9

About aesthetics I used the "long" form of all math statements, avoided the use of pointers, and used only while loops for aesthetic purposes (simply put, I think the code is prettier when it is written like that.) While making the code look aesthetically pleasing can be beneficial (especially if it makes it more readable), you should not give that a ...


8

It's a very unusual style to begin identifiers with uppercase letters. Include <stdbool.h> and use the bool type for flags. Many of the variables can be moved to smaller scopes. I think you should use for loops where appropriate - grouping the initialisation, predicate and advance clauses together improves clarity. Obviously this code lacks the ...


4

For another take on the same problem (sorting parallel arrays), see Quicksort template (for sorting corresponding arrays). Your code is strangely organized. I would expect it to have a single entry point, something like this: template<class Vector, class... Vectors> void parallel_sort(Vector& keyvector, Vectors&... vectors) { std::vector&...


3

I find the big points covered well: class and methods have one clear, documented purpose the API follows the well-known java.util.Arrays (if not to the point of documenting RuntimeExceptions thrown) I'd try to get rid of magic literals and code replication: size counts = new int[Byte.MAX_VALUE-Byte.MIN_VALUE+1] (or 1<<Byte.SIZE?), use for (int ...


3

I'll just review bubble_sort as an example. My quick notes: Add a useful docstring and/or types (I had to read the entire function to realize that it was a generator) When iterating over a range, use for in range rather than while. I also prefer using brief, generic variable names like i and j in lieu of names like index and test_index that are longer ...


2

Errors in the code This piece array(i) > array(pivot) .and. i <= length is not valid code. If i > length you will get an out of bounds access with array(i). If you rewrite it as i <= length .and. array(i) > array(pivot) it is still wrong, because there is no short circuiting in Fortran. Or to be more precise: Fortran operators are neither ...


2

Use <stdint.h> If your system has it, use it. I bet your long is probably the same as long long, but to be sure of what you're using, use intN_t. Use strtol safely: (This part is about OP's own answer; not the question itself, which doesn't use strtol()) Using strtol is good because it can be safer, but it is a pain in the ass to use it safely. ...


1

Firstly, refer my comment under your question: "Is there a good reason for parallel vectors at all? Or should it be a single vector of struct {int, int, ...}?" Assuming there is a good reason: Putting it all together, applying consistent style and making a few optimising tweak... I have "borrowed" from @Quuxplusone for the parallel_sort with C++17 "comma ...


1

First of all thanks to all the authors @user3629249 @G.Sliepen @chux-Reinstate Monica who provided valuable insights to the source-code of a command-line based merge-sort algorithm described in the Problem Description.. I have made important changes to the source code in order to make it better in terms of security, loopholes, buffer-overflows, ...


Only top voted, non community-wiki answers of a minimum length are eligible