Topic 9 I t d ti t R i Introduction to Recursion
"T ith h "To a man with a hammer, everything looks like a nail" everything looks like a nail
- Mark Twain
Mark Twain
CS 307 Fundamentals of Computer Science Introduction to Recursion
1
"To a man with a hammer, "T ith h everything looks like - - PowerPoint PPT Presentation
Topic 9 Introduction to Recursion I t d ti t R i "To a man with a hammer, "T ith h everything looks like a nail" everything looks like a nail -Mark Twain Mark Twain CS 307 Fundamentals of 1 Computer Science
CS 307 Fundamentals of Computer Science Introduction to Recursion
1
CS 307 Fundamentals of Computer Science Introduction to Recursion
2
CS 307 Fundamentals of Computer Science Introduction to Recursion
3
CS 307 Fundamentals of Computer Science Introduction to Recursion
4
CS 307 Fundamentals of Computer Science Introduction to Recursion
5
CS 307 Fundamentals of Computer Science Introduction to Recursion
6
CS 307 Fundamentals of Computer Science Introduction to Recursion
7
CS 307 Fundamentals of Computer Science Introduction to Recursion
8
CS 307 Fundamentals of Computer Science Introduction to Recursion
9
CS 307 Fundamentals of Computer Science Introduction to Recursion
10
– Hint: don't worry about any sub directories at first
public File[] getFiles() public Directory[] getSubdirectories()
bli i t tSi ()
CS 307 Fundamentals of Computer Science Introduction to Recursion
11
public int getSize()
CS 307 Fundamentals of Computer Science
Introduction to Recursion
12
m1.txt m2.txt A.pdf
AB.pdf a1.htm a2.htm a3.htm a4.htm
CS 307 Fundamentals of Computer Science Introduction to Recursion
13
CS 307 Fundamentals of Computer Science Introduction to Recursion
14
CS 307 Fundamentals of Computer Science
Introduction to Recursion
15
public int getDirectorySpace(Directory d) public int getDirectorySpace(Directory d) { ArrayList dirs = new ArrayList(); File[] fileList; Directory[] dirList; y dirs.add(d); Directory temp; int total = 0; hil ( ! di i () ) while( ! dirs.isEmpty() ) { temp = (Directory)dirs.remove(0); fileList = temp.getFiles(); for(int i = 0; i < fileList length; i++) for(int i 0; i < fileList.length; i++) total += fileList[i].getSize(); dirList = temp.getSubdirectories(); for(int i =0; i < dirList.length; i++) dirs.add( dirList[i] ); } return total; }
CS 307 Fundamentals of Computer Science Introduction to Recursion
16
}
CS 307 Fundamentals of Computer Science Introduction to Recursion
17
CS 307 Fundamentals of Computer Science Introduction to Recursion
18
CS 307 Fundamentals of Computer Science Introduction to Recursion
19
CS 307 Fundamentals of Computer Science Introduction to Recursion
20
CS 307 Fundamentals of Computer Science Introduction to Recursion
21
CS 307 Fundamentals of Computer Science Introduction to Recursion
22
CS 307 Fundamentals of Computer Science Introduction to Recursion
23
CS 307 Fundamentals of Computer Science Introduction to Recursion
24
CS 307 Fundamentals of Computer Science Introduction to Recursion
25
CS 307 Fundamentals of Computer Science Introduction to Recursion
26
CS 307 Fundamentals of Computer Science Introduction to Recursion
27
CS 307 Fundamentals of Computer Science Introduction to Recursion
28
CS 307 Fundamentals of Computer Science Introduction to Recursion
29
CS 307 Fundamentals of Computer Science Introduction to Recursion
30
CS 307 Fundamentals of Computer Science Introduction to Recursion
31
CS 307 Fundamentals of Computer Science Introduction to Recursion
32
CS 307 Fundamentals of Computer Science Introduction to Recursion
33
CS 307 Fundamentals of Computer Science Introduction to Recursion
34
CS 307 Fundamentals of Computer Science Introduction to Recursion
35
CS 307 Fundamentals of Computer Science Introduction to Recursion
36
CS 307 Fundamentals of Computer Science Introduction to Recursion
37
CS 307 Fundamentals of Computer Science Introduction to Recursion
38
CS 307 Fundamentals of Computer Science
Introduction to Recursion
39
CS 307 Fundamentals of Computer Science Introduction to Recursion
40
CS 307 Fundamentals of Computer Science Introduction to Recursion
41
CS 307 Fundamentals of Computer Science Introduction to Recursion
42
CS 307 Fundamentals of Computer Science Introduction to Recursion
43
CS 307 Fundamentals of Computer Science Introduction to Recursion
44
CS 307 Fundamentals of Computer Science Introduction to Recursion
45
CS 307 Fundamentals of Computer Science Introduction to Recursion
46
CS 307 Fundamentals of Computer Science Introduction to Recursion
47
CS 307 Fundamentals of Computer Science Introduction to Recursion
48
CS 307 Fundamentals of Computer Science Introduction to Recursion
49
CS 307 Fundamentals of Computer Science
Introduction to Recursion
50
CS 307 Fundamentals of Computer Science Introduction to Recursion
51
CS 307 Fundamentals of Computer Science Introduction to Recursion
52
CS 307 Fundamentals of Computer Science Introduction to Recursion
53
2
2 2 1 2 2
3 2 2 1 1 1 3
1
2
3 1 1 1 1
CS 307 Fundamentals of Computer Science Introduction to Recursion
54
CS 307 Fundamentals of Computer Science Introduction to Recursion
55