链表、递归复习笔记.docx

  1. 1、本文档共3页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
链表、递归复习笔记

链表A collection is an object that helps us organize and manage other objects一个集合是一个帮助我们组织其他对象的对象Recall that an object reference is a variable that stores the address of an object一个对象的引用是储存一个对象地址的变量A reference also can be called a pointer一个引用又被叫为指针References often are depicted graphically:引用通常被图形化的描述。Object references can be used to create links between objectsSuppose a class contains a reference to another object of the same class:对象引用可用于创建对象之间的链接,假设一个类包含一个同类另一个对象的地址集合是存放引用型数据的容器,因此一定程度上说它不可以存放基本类型。即class Node{ int info; Node next;}For example, the Student class should not have to store a link to the next Student object in the list(在链表中,学生类不应该储存在下一个链表对象中)Instead, use a separate node class with two parts:(单独的节点类有两个部分:)(大概如此不能用基本类型吧)a reference to an independent object(指向独立对象的引用)a link to the next node in the list(连接链表下一个节点的link)Each node is an object of a class that has two instance variables: one for the data and one for the link每个节点都是一个类的一个对象,它有两个实例变量:分别用于数据和链接驱动程序链表内容类,可以不用设置然后是node类,,总之可以写在一个界面中最少两个类。Using an inner class makes StringLinkedList self-contained because it doesnt depend on a separate file??Making the inner class private makes it safer from the point of view of information hiding(使用内部类更安全)存放对象与存放实例数据区别?????递归All recursive definitions have to have a non-recursive part called the base case(递归必须有基本事件)If they didnt, there would be no way to terminate the recursive path(否则无法中止,无限递归)Such a definition would cause infinite recursionThis problem is similar to an infinite loop, but the non-terminating loop is part of the definition itselfEach call to the method sets up a new execution environment, with new parameters and local variables每个调用方法设立一个新的执行环境,新的参数和局部变量As with any method call, when the method completes, control returns to the method that invoked it (which may be an earlier invocation of itself)与任何方法调用一样,当方法完成后,控制返回到调用它的方法(可能是早先调用本身)常见语句if (num == 1)(base case) result = 1; else result = num + sum (n-1);(调用自己)towersOfHanoi(N-1,from,spare,to

文档评论(0)

liangyuehong + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档