CHANGE algorithm for stack