tailieunhanh - Lecture Data structures and other objects using C++ - Chapter 9: Recursive thinking

Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences of a problem within the problem itself. This presentation gives an additional example, which is not in the book. | Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences of a problem within the problem itself. This presentation gives an additional example, which is not in the book. Recursive Thinking Data Structures and Other Objects Using C++ This lecture demonstrates a typical pattern that arises in recursive functions. The lecture can be given shortly before or shortly after the students have read Section . By the way, the book delays the introduction of recursion until just before trees. Our reasoning here is that recursive functions with linked lists can sometimes be bad programming practice because the run-time stack must grow to the length of the linked list (and iterative algorithms are usually just as easy). On the other hand, the depth of recursive tree algorithms is merely the depth of the tree (and equivalent iterative algorithms can be harder to program). A Car Object To start the example, think about your favorite family car In this lecture, we're going to design a recursive function which manipulates a new object called a Car. In order to explain the Car that I have in mind, think about your favorite family car. NOTE: In Powerpoint, the next few slides will automatically appear every few seconds. A Car Object To start the example, think about your favorite family car .let's try for something a bit more modern that this. A Car Object To start the example, think about your favorite family car .no, that's too conservative. A Car Object To start the example, think about your favorite family car .that's better! A Car Object To start the example, think about your favorite family car Imagine that the car is controlled by a radio signal from a computer I want you to imagine that this family car is being controlled by a radio signal coming from your computer. A Car Class class car { public: . . . }; To start the example, think about your favorite family car Imagine that . | Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences of a problem within the problem itself. This presentation gives an additional example, which is not in the book. Recursive Thinking Data Structures and Other Objects Using C++ This lecture demonstrates a typical pattern that arises in recursive functions. The lecture can be given shortly before or shortly after the students have read Section . By the way, the book delays the introduction of recursion until just before trees. Our reasoning here is that recursive functions with linked lists can sometimes be bad programming practice because the run-time stack must grow to the length of the linked list (and iterative algorithms are usually just as easy). On the other hand, the depth of recursive tree algorithms is merely the depth of the tree (and equivalent iterative algorithms can be harder to program). A Car Object To start the example, think .