cs231 Lecture Notes Week 1, Friday 1) review of recursion 2) discussion of hw1 Recursion and stack diagrams: 1) when you invoke a method you get an instance of the method that contains its parameters and local variables. 2) these instances go on a stack. 3) there had better be a base case, or the stack gets really big and causes a StackOverflowException. Example: factorial. public static int factorial (int n) { if (n == 0) { return 1; } else { int recurse = factorial (n-1); int result = n * recurse; return result; } } Two ways to interpret recursive programs: 1) follow the stack 2) leap of faith Quizzes 8 and 9 Homework 1 ---------- Start with the card class in Chapter 12 of the old edition, Chapter 11 of the new edition. The concept of a Deck is implemented as an array of Card objects. First step is to change the implementation by creating a new object named Deck that contains an array of cards as an instance variable. Review: 1) how do you create a new object type? 2) what is an instance variable? 3) what is the syntax for referring to an instance variable? Homework big picture: 1) break Card class into two classes, Card and Deck. 2) move some of the methods into the Deck class 3) patch up the syntax to make it all work again 4) test the program, making sure all paths of execution get tested 5) implement mergesort -- it will be different this time because it will be in the Deck class Coming next week -- object methods!