refer to geeksforgeeks.org, note when using p = p->next, make sure that p->next do not be change in the loop