




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、DYNAMIC DATA STRUCTURES A data structure is a construct used to organize data in a specific way. So in this chapter we will: Become familiar with vectors and how they are used in Java. Learn what a linked data structure is and how it can be realized in Java. Find out how to manipulate linked lists L
2、earn what iterators are and how to create and use them CHAPTER 10简介 集合 将多个元素组成一个单元的对象 用于存储、检索、操纵和传输数据 集合框架 提供用于管理对象集合的接口和类 包括接口、实现和算法体系结构 用于操纵集合的接口CollectionSetListSortedSetMapSortedMapCollection接口 集合框架的根 通用方法 boolean contains(Object a) boolean equals(Object a) Iterator iterator() int size() void cl
3、ear() boolean add(Object a) Set接口 扩展Collection接口 不允许重复元素 对 add()、equals() 和 hashcode() 方法添加了限制 HashSet和TreeSet是Set的实现SortedSet接口 扩展了Set接口 元素按升序排序 重要异常 ClassCastException NullPointerException List接口 2-1 具有顺序的集合 扩展了Collection接口 元素可以通过其整型下标访问 可以包含重复元素List接口 2-2 方法分类 定位方法get()、set()、add()、remove()、addAl
4、l() 搜索方法indexOf() 和和 lastIndexOf() ListIterator方法listIterator() 和和 subList() Map接口 将键映射至值的对象 每个键最多都只能映射至一个值 重要方法 基本操作 put()、get()、remove()、containsKey()、containsValue()、size() 和和 isEmpty() 批操作 putAll() 和和 clear() 集合视图 keySet()、values() 和和 entrySet() 实现 2-1 用于存储集合的实际数据对象 重要集合类 AbstractCollection类提供Co
5、llection接口的框架实现 AbstractList 类提供 List 接口的框架实现 AbstractSequentialList 类是 List 接口的实现 LinkedList 类提供多个方法,用于在列表开始处和结尾 处获得、删除和插入元素简介 集合 将多个元素组成一个单元的对象 用于存储、检索、操纵和传输数据 集合框架 提供用于管理对象集合的接口和类 包括接口、实现和算法体系结构 用于操纵集合的接口CollectionSetListSortedSetMapSortedMapCollection接口 集合框架的根 通用方法 boolean contains(Object a) boo
6、lean equals(Object a) Iterator iterator() int size() void clear() boolean add(Object a) Set接口 扩展Collection接口 不允许重复元素 对 add()、equals() 和 hashcode() 方法添加了限制 HashSet和TreeSet是Set的实现SortedSet接口 扩展了Set接口 元素按升序排序 重要异常 ClassCastException NullPointerException List接口 2-1 具有顺序的集合 扩展了Collection接口 元素可以通过其整型下标访问
7、可以包含重复元素List接口 2-2 方法分类 定位方法get()、set()、add()、remove()、addAll() 搜索方法indexOf() 和和 lastIndexOf() ListIterator方法listIterator() 和和 subList() Map接口 将键映射至值的对象 每个键最多都只能映射至一个值 重要方法 基本操作 put()、get()、remove()、containsKey()、containsValue()、size() 和和 isEmpty() 批操作 putAll() 和和 clear() 集合视图 keySet()、values() 和和 e
8、ntrySet() 实现 2-1 用于存储集合的实际数据对象 重要集合类 AbstractCollection类提供Collection接口的框架实现 AbstractList 类提供 List 接口的框架实现 AbstractSequentialList 类是 List 接口的实现 LinkedList 类提供多个方法,用于在列表开始处和结尾 处获得、删除和插入元素实现 2-2 重要集合类(续) ArrayList 类是 List 接口的可变大小数组实现 AbstractSet 类提供 Set 接口的框架实现 HashSet 类为基本操作提供固定时间性能 TreeSet 类确保排序集将按元素
9、升序exampleimport java.util.*;public class ListOper public static void main(String args) if(args.length=0) System.out.println(你必须提供列表元素,作为命令行参数。请重试!你必须提供列表元素,作为命令行参数。请重试!); System.exit(0); System.out.println(); List l=new ArrayList(); for(int i=0;iB else hanno(A,C,B,n-1); move(A,B);hanno(C,B,A,n1); RE
10、CURSIONSuccessful Recursion A define of a method that includes a recursive invocation of the method being defined will not behave correctly unless you follow some specific design guidelines. The follwing rules apply to most cases that involve recursion. The heart of the method definition can be an i
11、f-else-statement or some other branching statement that leads to different cases, depending on some property of a parameter to the method being defiend.Successful Recursion 2 One or more of the brances include a recursive invocation of the method. These recursive invocations should in some sense use
12、 “smaller” arguments or solve “smaller” versions of the task performed by the method. One or more branches should include no recursive invocations. These are the stopping cases (alse known as the base cases.)Stack Overflow When a method invocation leads to infinite recursion, your program is likely
13、to end with an error message that refers to a “stack overflow”. The term stack refers to a data structure that is used to keep track of recursive calls (and other things as well). Intuitively a record of each recursive call is stored on something analogous to a piece of paper. These pieces of paper
14、are intuitively stacked one on top of the other. When this “stack” becomes too large for the computer to handle, that is called a stack overflow.Summary Vectors can be thought of as arrays that can grow in length. The base type of all vectors is Object. Thus, the elements of a vector may be of any c
15、lass type, but they cannot be of a primitive type. A linked list is a data structure consisting of objects known as nodes, such that each node can contain data and such that each node has a reference to one other node so that the entire linked list forms a list.Summary You can make a linked list sel
16、f-contained by making the node class an inner class of the linked class. You can use an iterator to step through the elements of a collection, such as the elements in a linked list.Summary If a method definition includes an invocation of the very method being defined, that is called a recursive call
17、. Recursive calls are legal in Java and can somethimes make a method definition clearer. In order to avoid infinite recursion, a recursive method definition should contain two kinds of cases: one or more case that include recursive call(s) and one or more stopping cases that do not involve any recur
18、sive calls.Self-test Question Suppose v is a vector. How do you add the string “Hello” to the vector v? If you create a vector with the following, can the vector contain more than 20 elements? Vector v=new Vector(20); What is the base type of a vector? Can you store a value of type int in a vector? Suppose v is a vector. What is the difference between v.capacity() and v.size()?Self-test Question Why does th
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025河南陆军第八十三集团军医院招聘34人考前自测高频考点模拟试题及答案详解(各地真题)
- 2025福建漳州长运高中招聘21人模拟试卷附答案详解(典型题)
- 2025广东深圳大学人文学院李立教授团队博士后招聘1人模拟试卷含答案详解
- 2025广东佛山市顺德区乐从第一实验学校临聘教师招聘考前自测高频考点模拟试题及答案详解(历年真题)
- 2025湖南株洲市自然资源和规划局选聘模拟试卷及答案详解(名校卷)
- 2025广西北部湾大学招聘高层次人才53人模拟试卷及答案详解一套
- 2025河北秦皇岛市北兴企业管理咨询有限公司招聘派遣制人员4人考前自测高频考点模拟试题附答案详解
- 2025年甘肃省庆阳市西峰区招聘城镇公益性岗位20人考前自测高频考点模拟试题及一套答案详解
- 2025湖南长沙浏阳市审计局人员模拟试卷及答案详解(历年真题)
- 2025河南省中医院(河南中医药大学第二附属医院)招聘博士研究生64人模拟试卷附答案详解(模拟题)
- GB/T 21181-2025再生铅锭
- 2025年酒水行业精酿啤酒市场前景研究报告
- 西游记大闹通天河课件
- 《互换性与测量技术》课件-Lesson 09 第五章 公差原则
- 仪器仪表安全培训课件
- 交谊舞教学课件下载
- 触电急救培训课件模板
- 2025-2030肉牛养殖大数据平台建设与数字化管理转型路径研究报告
- 新加坡cpa教学法课件
- GB/T 9943-2025高速工具钢
- 医院医疗设备购置论证报告
评论
0/150
提交评论