replace the stack inside the compare for loop