refactor method of getting the element in to top of stack
simple binary search