1 / 4

What we will do today

What we will do today. You’ll try to write a recursive function to solve a simple problem We’ll return to the count number of “ a”s example from the previous day, and I’ll explore it a bit more I’ll discuss an alternative recursive string function

hamish
Télécharger la présentation

What we will do today

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. What we will do today • You’ll try to write a recursive function to solve a simple problem • We’ll return to the count number of “a”s example from the previous day, and I’ll explore it a bit more • I’ll discuss an alternative recursive string function • I’ll discuss the “natural” recursive structure of files and directories, and go through a example with that • You will also write a recursive function with files and directories • If we have time: even more practice with recursive functions

  2. First Recursion Problem • Go to http://codingbat.com/java/Recursion-1 • Solve count7 • If you finish, solve bunnyEars2 • If you finish, do fibonacci (this one is so old that I solved in my very first CS class…and it was pretty dang old then) • If you finish, do a tiny green dance in your chair and then move on to some more

  3. publicintcountAs(String input) { if(input.isEmpty()) return 0; String restOfString = input.substring(1); intrestOfStringCount = countAs(restOfString); if(input.charAt(0) == 'a') { returnrestOfStringCount + 1; } else { returnrestOfStringCount; } }

  4. A genuinely good example of recursion How would you find the largest file within a directory (oh, and this directory can contain other directories)

More Related