added sorting according to delta in c++ version of scaleproc