




版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
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簡(jiǎn)介 集合 將多個(gè)元素組成一個(gè)單元的對(duì)象 用于存儲(chǔ)、檢索、操縱和傳輸數(shù)據(jù) 集合框架 提供用于管理對(duì)象集合的接口和類(lèi) 包括接口、實(shí)現(xiàn)和算法體系結(jié)構(gòu) 用于操縱集合的接口CollectionSetListSortedSetMapSortedMapCollection接口 集合框架的根 通用方法 boolean contains(Object a) boolean equals(Object a) Iterator iterator() int size() void cl
3、ear() boolean add(Object a) Set接口 擴(kuò)展Collection接口 不允許重復(fù)元素 對(duì) add()、equals() 和 hashcode() 方法添加了限制 HashSet和TreeSet是Set的實(shí)現(xiàn)SortedSet接口 擴(kuò)展了Set接口 元素按升序排序 重要異常 ClassCastException NullPointerException List接口 2-1 具有順序的集合 擴(kuò)展了Collection接口 元素可以通過(guò)其整型下標(biāo)訪(fǎng)問(wèn) 可以包含重復(fù)元素List接口 2-2 方法分類(lèi) 定位方法get()、set()、add()、remove()、addAl
4、l() 搜索方法indexOf() 和和 lastIndexOf() ListIterator方法listIterator() 和和 subList() Map接口 將鍵映射至值的對(duì)象 每個(gè)鍵最多都只能映射至一個(gè)值 重要方法 基本操作 put()、get()、remove()、containsKey()、containsValue()、size() 和和 isEmpty() 批操作 putAll() 和和 clear() 集合視圖 keySet()、values() 和和 entrySet() 實(shí)現(xiàn) 2-1 用于存儲(chǔ)集合的實(shí)際數(shù)據(jù)對(duì)象 重要集合類(lèi) AbstractCollection類(lèi)提供Co
5、llection接口的框架實(shí)現(xiàn) AbstractList 類(lèi)提供 List 接口的框架實(shí)現(xiàn) AbstractSequentialList 類(lèi)是 List 接口的實(shí)現(xiàn) LinkedList 類(lèi)提供多個(gè)方法,用于在列表開(kāi)始處和結(jié)尾 處獲得、刪除和插入元素簡(jiǎn)介 集合 將多個(gè)元素組成一個(gè)單元的對(duì)象 用于存儲(chǔ)、檢索、操縱和傳輸數(shù)據(jù) 集合框架 提供用于管理對(duì)象集合的接口和類(lèi) 包括接口、實(shí)現(xiàn)和算法體系結(jié)構(gòu) 用于操縱集合的接口CollectionSetListSortedSetMapSortedMapCollection接口 集合框架的根 通用方法 boolean contains(Object a) boo
6、lean equals(Object a) Iterator iterator() int size() void clear() boolean add(Object a) Set接口 擴(kuò)展Collection接口 不允許重復(fù)元素 對(duì) add()、equals() 和 hashcode() 方法添加了限制 HashSet和TreeSet是Set的實(shí)現(xiàn)SortedSet接口 擴(kuò)展了Set接口 元素按升序排序 重要異常 ClassCastException NullPointerException List接口 2-1 具有順序的集合 擴(kuò)展了Collection接口 元素可以通過(guò)其整型下標(biāo)訪(fǎng)問(wèn)
7、可以包含重復(fù)元素List接口 2-2 方法分類(lèi) 定位方法get()、set()、add()、remove()、addAll() 搜索方法indexOf() 和和 lastIndexOf() ListIterator方法listIterator() 和和 subList() Map接口 將鍵映射至值的對(duì)象 每個(gè)鍵最多都只能映射至一個(gè)值 重要方法 基本操作 put()、get()、remove()、containsKey()、containsValue()、size() 和和 isEmpty() 批操作 putAll() 和和 clear() 集合視圖 keySet()、values() 和和 e
8、ntrySet() 實(shí)現(xiàn) 2-1 用于存儲(chǔ)集合的實(shí)際數(shù)據(jù)對(duì)象 重要集合類(lèi) AbstractCollection類(lèi)提供Collection接口的框架實(shí)現(xiàn) AbstractList 類(lèi)提供 List 接口的框架實(shí)現(xiàn) AbstractSequentialList 類(lèi)是 List 接口的實(shí)現(xiàn) LinkedList 類(lèi)提供多個(gè)方法,用于在列表開(kāi)始處和結(jié)尾 處獲得、刪除和插入元素實(shí)現(xiàn) 2-2 重要集合類(lèi)(續(xù)) ArrayList 類(lèi)是 List 接口的可變大小數(shù)組實(shí)現(xiàn) AbstractSet 類(lèi)提供 Set 接口的框架實(shí)現(xiàn) HashSet 類(lèi)為基本操作提供固定時(shí)間性能 TreeSet 類(lèi)確保排序集將按元素
9、升序exampleimport java.util.*;public class ListOper public static void main(String args) if(args.length=0) System.out.println(你必須提供列表元素,作為命令行參數(shù)。請(qǐng)重試!你必須提供列表元素,作為命令行參數(shù)。請(qǐng)重試!); 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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 高速鐵路設(shè)備采購(gòu)合同終止及運(yùn)營(yíng)維護(hù)協(xié)議
- 餐飲業(yè)專(zhuān)用商業(yè)房產(chǎn)租賃協(xié)議書(shū)
- 老人兒童護(hù)理課件
- 美術(shù)課件彩虹模板
- 公司獎(jiǎng)勵(lì)規(guī)章制度
- 生產(chǎn)車(chē)間10s管理制度
- 企業(yè)金融安全
- 建筑施工vr安全體驗(yàn)館
- 安全防范系統(tǒng)報(bào)告
- 2025年上半年征兵工作總結(jié)
- 燃?xì)獍踩嘤?xùn)課件
- 酒店安全風(fēng)險(xiǎn)辨識(shí)與預(yù)防制度
- 企業(yè)員工心理危機(jī)干預(yù)
- 330kV變電站運(yùn)營(yíng)維護(hù)管理方案
- 拋石擠淤及基礎(chǔ)大開(kāi)挖施工方案
- 路燈拆裝合同范文
- 《動(dòng)火作業(yè)安全培訓(xùn)》課件
- 2025年中考語(yǔ)文備考之12部名著閱讀習(xí)題及參考答案
- 1998-2017年中科院植物學(xué)考研真題及答案匯編
- 兒童相機(jī)市場(chǎng)的發(fā)展趨勢(shì)分析
- 血液凈化護(hù)理知識(shí)競(jìng)賽考試題庫(kù)500題(含答案)
評(píng)論
0/150
提交評(píng)論