




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
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年教導處教學設備升級計劃
- 風電施工技術標準化方案和措施
- 十四五規劃人才培養心得體會
- 以小組合作之翼展初中數學課堂新程
- 以客戶價值為核心的產品規劃創新方法與實踐探究
- 2025至2030年中國電子設計自動化(EDA)軟件產業發展預測及投資策略分析報告
- 浙江省湖州市德清縣2024-2025學年小升初必考題數學檢測卷含解析
- 醫師定期考核操作流程
- 剖宮產手術圍手術期預防用抗菌藥物管理實施細則
- 2024北京海淀區高一(下)期末英語試題和答案
- 2025年河北軌道運輸職業技術學院單招職業技能考試題庫及答案1套
- 煤礦工作申請書
- 韶關拆除廠房施工方案
- 加油站的運營數據分析
- 食品安全日管控、周排查及月調度記錄表
- IATF 16949 質量管理手冊
評論
0/150
提交評論