# Tag Info

1 vote

### Bellman-Ford optimisation in C with Shortest Path Algorithm (SPFA) and Small Label first (SLF)

Concerning *alloc() discussion, (not a major issue with OP's code) Recommend: No cast Size to the referenced object, not type. Check result Lead any size ...
Accepted

### Tar implementation

What’s the Deal Here Tail recursion is an extremely useful pattern. You’d normally use it to transform a loop into an equivalent function that calls itself. All the state that carries over from one ...
• 3,446

### Tar implementation

The recursion here is not tail recursion. A tail-call is one where no further processing is needed between the called function's return and that of the calling function (this means that the current ...
• 67.7k

### Bellman-Ford optimisation in C with Shortest Path Algorithm (SPFA) and Small Label first (SLF)

We're missing a lot of includes. At least the following standard headers: ...
• 67.7k

### Bellman-Ford optimisation in C

for (uint _ = 0; _ < nb_nodes - 1; _++) Maybe this was python code translated into C?!? Repect the norms of the community. Even though ...
• 8,970

### Bellman-Ford optimisation in C

A few pieces of advice you can consider: As far as I'm aware, documentation comments are conventionally immediately before the declaration, not between the signature and the body of the ...
• 1,546

### Compute the sum of even numbers between two values

Just some corner thoughts Overflow sumOnlyEvenNumbersInRange(INT_MAX, INT_MAX) incurs signed integer overflow with ...

### Compute the sum of even numbers between two values

The Math Pardon if you already know this, but: the usual way to solve for a closed-form solution for a series like this is to note that the sum of a series that grows at a linear rate will be ...
• 3,446
Accepted

### Compute the sum of even numbers between two values

The first implementation mixes integer and floating-point arithmetic. I definitely would avoid that. The other two versions both use >> on a signed type (<...
• 67.7k

### In-place recursive quick sort in C

Still looks pretty good! Beware Mixing Signed and Unsigned Integers Because of the default type-conversion rules, you could get bugs like the famous 3U < -1. ...
• 3,446
Accepted

### Damerau-Levenshtein distance performance improvements

Please write this int min_int(int arr[], size_t size) { assert(size > 0); That will avoid UB, and give the caller a nice diagnostic if he messes up his ...
• 8,970

### In-place recursive quick sort in C

No naked loops Every loop implements an important algorithm, and therefore deserves a name. In your case, the loop ...
• 54.6k

### In-place recursive quick sort in C

General Observations Good use of the current C programming standard. The code is basically well written, but variable names could be improved, at least in main(). I ...
• 21.9k

### Run command in a child process

Unnedded -1 No need to subtract 1. The fgets function reads at most one less than the number of characters specified by n from ...
1 vote

### Solution to Codejam 2021 1C (Closest Pick) in C

We don't really need to store and sort the entire list of gaps. We're just interested in the largest gap we can cover with two tickets (that's max_gap_size) and ...
• 67.7k

### Solution to Codejam 2021 1C (Closest Pick) in C

Common mistakes This echoes @Haris Enable more compiler warnings: As part of a code review, when such trivial errors are found so readily, it casts an overall disappointment on code. Avoid the 3 ...

### quadratic probing hashmap and its time efficiency

Minor stuff: IsPrime(1) is usually considered false ...

### Run command in a child process

Use posix_spawn Or possibly posix_spawnp. It’s in the POSIX standard precisely to take care of this. You don’t need to reinvent ...
• 3,446

### quadratic probing hashmap and its time efficiency

Quadratic probing uses as the $i$th offset from the first probe index $\pm 1^ic_2i^2+c_1i+c_0, c_2\ne 0$ with parentheses inserted as deemed useful. ...
• 5,363

### Run command in a child process

Code risks invoking undefined behaviour: if (argc != 2) { printf("Usage: %s <0|1|2|3>\n", argv[0]); return EXIT_FAILURE; } Dereferencing <...
• 807

### Run command in a child process

We need to enable more compiler warnings - these problems are trivially fixed: ...
• 67.7k
Accepted

### Solution to Codejam 2021 1C (Closest Pick) in C

Enable more compiler warnings GCC reports some warnings: ...
• 807

### quadratic probing hashmap and its time efficiency

General Observations Interesting question! As the comments show, a lot of room for learning! Consistency! Some header files are using Doxygen Comments, other headers are not, some header files don't ...
• 21.9k

### Max-heap implementation in C

The biggest issue I see here, and is not yet commented on, is the call to realloc for every insertion. When you remove an element from the heap, the ...
• 4,302
1 vote

### Max-heap implementation in C

Avoid FP math for an integer problem floor(log2(max_heap->size)) is overkill and at some level risks incorrect results with less than ideal FP functions. A ...
1 vote

### Follow up: A chat server using the select() API

Undefined Behavior: ...
• 807

### Create a structure to store student data and display all the records in the array

I'm just going to look at the AssignGrade() function. ...
• 879

### Max-heap implementation in C

General Observations Since this might be a set of library routines, it might be a good idea to move all the heap related functions to their own .c file and have a ...
• 21.9k
Accepted

### Max-heap implementation in C

This is a max-heap datastructure, and there is very consistent nomenclature here which reflects that. I'm sure it is clear and commendable. But I wouldn't have minded seeing it written in a comment, ...
• 8,970

### Create a structure to store student data and display all the records in the array

General Observations The code might be more readable if the indentation was 4 spaces rather than only 2 spaces. Many programmers use a tab for indentation. It is also common to have spaces between the ...
• 21.9k

### Create a structure to store student data and display all the records in the array

Undefined Behavior s[i].name[50] = ' '; This accesses outside of the array bounds. fflush(stdin); This is undefined behavior. ...
• 601

Improve naming uniformity Instead of .... netstring_internal.h _INTERNAL_NETSTRING_H netstr_error NETSTR_PROTO protocol_table netstring_to_addrinfo.c DOMAIN_BUFSIZ ...

### Stack using doubly linked list

A stack should be a vector (that is, a dynamically-allocated array that remembers its size and capacity). Pop by decrementing the size. Push by reallocating if necessary and incrementing the size. ...
• 3,446
1 vote

### Array List C implementation

Give Your Structures More Informative Names This is a dequeue, not a list. The Java class named ArrayList doesn’t have ...
• 3,446
1 vote

### Array List C implementation

A few more points: In al_new you could use calloc to zero list->array and avoid the explicit loop to do so. I think you ...
• 879
1 vote

### Stack using doubly linked list

Consider a uniform name space Code such as this is not used in isolation, but with other code. The names chosen readily collide (like top) with existing code and ...
Accepted

### Binary Search Tree implementation in C [1]

Fix compilation warnings If your compiler isn't telling you about these, you haven't enabled enough warnings: BST* create_bst(void) { /*🔺🔺🔺*/ <...
• 67.7k

Two minor points about this bit: #if(_POSIX_C_SOURCE != 200112L) #undef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200112L #endif First, if you define ...
• 3,446

Declare only where needed: //long port; //port = strtol(*str, (char **) str, ...); long port = strtol(*str, (char **) str, ...); Simplify initialization: ...
• 807

There's a subtle mistake in this macro definition: #define ARRAYSIZE(x) (sizeof(x) / sizeof(x[0])) When we put parens around the expansions of macro arguments, ...
• 67.7k
Accepted

Why not always use getaddrinfo()? I kept the version with struct sockaddr_storage anyway Why? It is inferior in every possible ...
• 42.5k
Accepted

### Command line calculator in C

Avoid global variables for this task The key problem, in this case, is the added difficultly in proving code correctness. Alternative: In func(), instead of ...

### Command line calculator in C

Don't write clever code: if (printf("%g\n", b(&(const char *){*argv}, 0)) < 0) You know you’re brilliant, but maybe you’d like to understand what ...
• 807

### Command line calculator in C

General Observations I'm going to address coding style here, since the code is almost unreadable. If you are interested in getting your code reviewed you may want to pay attention to what the ...
• 21.9k
1 vote

### Brute Force Algorithm in C

This part of the code has a common beginner error: ...
• 67.7k
Accepted

### Basic recursive descent parser in C

Portable? "I wrote this code with portability in mind," --> Standard C lacks EINVAL. longjmp(jmp, errno = EINVAL); ...

### Recursive merge sort in C

This is a Great First Program in C I don’t think I’ve seen a better one. However, I’ll suggest some improvements. Write Contracts for your Functions These can be short and sweet; names like ...
• 3,446