1 Joe Meehean. call themselves directly or indirectly void f(){... f();... } void g(){... h();......

42
Recursion 1 Joe Meehean

Transcript of 1 Joe Meehean. call themselves directly or indirectly void f(){... f();... } void g(){... h();......

CS242 Data Structures II

Recursion1Joe Meehean

Recursive Methodscall themselves directlyor indirectly

void f(){ ... f(); ...}void g(){ ... h(); ...}

void h(){ ... g(); ...}Recursive Method Exampleint factorial(int x){ int handback; if( x llovoid printStr(string s, int k){ if( k >= s.length() ) return; cout = s.length() ) return; cout = s.length() ) return; cout