implementing heap; both functional and array