the C code of Algorithm