diff --git a/greedy_algorithms/jumpgame.cpp b/greedy_algorithms/jumpgame.cpp index b3d2c4420..94b3b2685 100644 --- a/greedy_algorithms/jumpgame.cpp +++ b/greedy_algorithms/jumpgame.cpp @@ -9,6 +9,7 @@ #include #include +#include //Implements the algorithm /*We name the indices good and bad based on whether we can reach the destination if we start at that position. @@ -19,7 +20,7 @@ *After the end of the loop, if we reach the lastPos as 0, then the destination can be reached from the start position. */ /** - * This function implements the above algorithm + * @brief This function implements the above algorithm * @param vector of nums containing the maximum jump (in steps) from that index * @return returns bool value whether final index can be reached or not */ @@ -33,13 +34,35 @@ bool canJump(std::vector nums) { return lastPos == 0; } + +/** + * @brief Function to test above algorithm + */ +void test(){ + //Test 1 + std::vector num1={4,3,1,0,5}; + assert(canJump(num1)==true); + std::cout<<"Input: "; + for(auto i: num1){ + std::cout< num2={3,2,1,0,4}; + assert(canJump(num2)==false); + std::cout<<"Input: "; + for(auto i: num2){ + std::cout< num={4,3,1,0,5}; - std::cout<