update stack[i] and reordering