LectureFourteen - Lecture 14 Functions – Part IV By Ghada...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lecture 14 Functions – Part IV By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department The Hashemite University 2 Outline ¡ Recursion. ¡ Functions with empty parameter lists. ¡ Inline functions. The Hashemite University 3 Recursion I ¡ Recursive functions ¡ Are functions that calls themselves. ¡ Can only solve a base case. ¡ If not base case, the function breaks the problem into a slightly smaller, slightly simpler, problem that resembles the original problem and ¡ Launches a new copy of itself to work on the smaller problem, slowly converging towards the base case ¡ Makes a call to itself inside the return statement ¡ Eventually the base case gets solved and then that value works its way back up to solve the whole problem. ¡ The recursion step executes while the original call to the function is still open (not finished yet). The Hashemite University 4 Recursion II ¡ Example: factorial n! = n * ( n – 1 ) * ( n – 2 ) * … * 1 ¡ Can be solved either iteratively or recursively: ¡ Iteratively: int factorial = 1; for (int count = n; count >= 1; count--) factorial *= count;...
View Full Document

Page1 / 13

LectureFourteen - Lecture 14 Functions – Part IV By Ghada...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online