it works!
introduce pre pointer to improve algorithm
error fixed. works