algorithm-archivists / algorithm-archive

A collaborative book on algorithms
https://www.algorithm-archive.org
MIT License
2.35k stars 354 forks source link

Fix warnings and remove VLA on C++ Thomas algorithm #932

Closed ShadowMitia closed 2 years ago

ShadowMitia commented 2 years ago

This PR fixes warnings generated by the code, and removes a variable length array which is not legal in C++ (it's a compiler extension, which most of them do have, but is not strictly speaking C++).

I've also constified and added references where I thought it would be best applicable.

The only part I'm not sure of is :

for (int i = static_cast<int>(size) - 2; i >= 0; --i) {

and my use of the static_cast. size is a std::size_t and we can't just have i be one too (or any unsigned) because of overflow issues which would break the condition. I'm not sure what's the best thing to do in this scenario. My guess is it's generally fine, and you should only be worried on very large arrays. Which is not the point here.