Tom Forsyth's Linear-Speed Vertex Cache Optimisation algorithm implementation by Martin Storsjo in header file single-file library.
Add #define FORSYTH_IMPLEMENTATION
before #include "forsyth.h"
in one .c or .cpp file to create the implementation.
Usage:
forsythReorderIndices(outIndices, indices, numTriangles, numVertices);