Write an algorithm for PUP operation in stack