|
|
solve( n ) { Sol s1, s2, s3, ...; Sol sol; /* ================================================= Take care of the "base cases" seperately (this will stop the "infinite recursion" problem ================================================== */ if ( n == a base_case ) { return ( base_case_solution(n) ); // Base case } /* =================================================== This is the recursive solver =================================================== */ /* --------------------------------------- Solve smaller problems (divide step) --------------------------------------- */ s1 = solve( n-1 ); // s1 = the solution of smaller problem "n-1" s2 = solve( n-2 ); // s2 = the solution of smaller problem "n-2" s3 = solve( n-3 ); // s3 = the solution of smaller problem "n-3" .... /* ---------------------------------------------- Use the solutions for the smaller problems to solve the ORIGINAL problem (conquer step) ----------------------------------------------- */ sol = combine( s1, s2, s3, ..... ); /* ---------------------------- Return the solution... ---------------------------- */ return (sol); } |