reverse a sequence using stack