algorithms implement in C