Written heap ,calculation functions and datastructures (Not Tested)