C code for Johnson's 1975 algorithm