




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(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ì)象集合的接口和類 包括接口、實(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接口 元素可以通過其整型下標(biāo)訪問 可以包含重復(fù)元素List接口 2-2 方法分類 定位方法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ì)象 重要集合類 AbstractCollection類提供Co
5、llection接口的框架實(shí)現(xiàn) AbstractList 類提供 List 接口的框架實(shí)現(xiàn) AbstractSequentialList 類是 List 接口的實(shí)現(xiàn) LinkedList 類提供多個(gè)方法,用于在列表開始處和結(jié)尾 處獲得、刪除和插入元素簡(jiǎn)介 集合 將多個(gè)元素組成一個(gè)單元的對(duì)象 用于存儲(chǔ)、檢索、操縱和傳輸數(shù)據(jù) 集合框架 提供用于管理對(duì)象集合的接口和類 包括接口、實(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接口 元素可以通過其整型下標(biāo)訪問
7、可以包含重復(fù)元素List接口 2-2 方法分類 定位方法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ì)象 重要集合類 AbstractCollection類提供Collection接口的框架實(shí)現(xiàn) AbstractList 類提供 List 接口的框架實(shí)現(xiàn) AbstractSequentialList 類是 List 接口的實(shí)現(xiàn) LinkedList 類提供多個(gè)方法,用于在列表開始處和結(jié)尾 處獲得、刪除和插入元素實(shí)現(xiàn) 2-2 重要集合類(續(xù)) ArrayList 類是 List 接口的可變大小數(shù)組實(shí)現(xiàn) AbstractSet 類提供 Set 接口的框架實(shí)現(xiàn) HashSet 類為基本操作提供固定時(shí)間性能 TreeSet 類確保排序集將按元素
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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 衛(wèi)生管理職業(yè)素養(yǎng)試題及答案
- 做賬實(shí)操-關(guān)稅調(diào)研報(bào)告
- 做賬實(shí)操-關(guān)稅對(duì)外貿(mào)受益股的影響分析
- 海外專利申請(qǐng)中的法律問題探討試題及答案
- 激光工程項(xiàng)目管理基本要求試題及答案
- 衡陽日?qǐng)?bào)面試題及答案
- 職業(yè)心理素質(zhì)評(píng)估工具試題及答案
- 船舶原理試題庫及答案
- 激光技術(shù)工程師考試的時(shí)間管理與試題及答案
- 復(fù)習(xí)策略與護(hù)士資格證考試相關(guān)的試題答案
- 生產(chǎn)節(jié)拍計(jì)算表格
- 高中語文中職語文《廉頗藺相如列傳》課件-完美版
- FZT 74005-2016 針織瑜伽服行業(yè)標(biāo)準(zhǔn)
- 2024年湖北省武漢市高考數(shù)學(xué)一調(diào)試卷
- 13區(qū)域分析與區(qū)域規(guī)劃(第三版)電子教案(第十三章)
- JJG 4-2015鋼卷尺行業(yè)標(biāo)準(zhǔn)
- 《公路橋涵養(yǎng)護(hù)規(guī)范》(JTG5120-2021)
- 晉升羽毛球一級(jí)裁判員考試試題
- 【課件】文明的瑰寶(藝術(shù)色彩)課件高中美術(shù)人教版(2019)選擇性必修1+繪畫
- 胰腺炎的中醫(yī)特色護(hù)理
- 世界強(qiáng)企業(yè)管理制度管理表格全集
評(píng)論
0/150
提交評(píng)論