Recursive shortest path finding in a matrix(programming module assignment)