1 / 38

新世代計算機概論第三版

新世代計算機概論第三版. 第 13 章 資料結構. 13-1  陣列. 一個完整的資料結構 (data structure) 必須包含資料、相關運算的定義及函數。 陣列 (array) 和變數一樣是用來存放資料,不同的是陣列雖然只有一個名稱,卻能夠用來存放多個資料,這些資料叫做元素 (element) ,陣列是透過索引 (index) 來區分各個元素。 當陣列最多能夠存放 n 個元素時,表示它的長度 (length) 為 n ,而且除了一維 (one-dimension) 陣列之外,大部分程式語言亦支援多維 (multi-dimension) 陣列。.

mac
Télécharger la présentation

新世代計算機概論第三版

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 新世代計算機概論第三版 第13章 資料結構

  2. 13-1 陣列 • 一個完整的資料結構 (data structure) 必須包含資料、相關運算的定義及函數。 • 陣列 (array) 和變數一樣是用來存放資料,不同的是陣列雖然只有一個名稱,卻能夠用來存放多個資料,這些資料叫做元素 (element),陣列是透過索引 (index) 來區分各個元素。 • 當陣列最多能夠存放n個元素時,表示它的長度 (length) 為n,而且除了一維 (one-dimension) 陣列之外,大部分程式語言亦支援多維 (multi-dimension) 陣列。

  3. 一維陣列的記憶體配置

  4. 陣列的應用 • 存放多項式

  5. 存放稀疏矩陣

  6. 陣列的定址方式

  7. 13-2 堆疊

  8. 堆疊經常應用於下列幾個方面: • 資料反轉 (data reversing) • 回溯 (backtracking) • 資料剖析 (data parsing) • 運算式表示法轉換 • 中序表示法 (infix) • 前序表示法 (prefix) • 後序表示法 (postfix)

  9. 使用堆疊將運算式A * (B + C) - D由中序表示法轉換成後序表示法:

  10. 系統堆疊

  11. 13-3 佇列

  12. 13-4 鏈結串列

  13. 13-5 樹 • 樹是由一個或多個節點所組成的有限集合 • 祖先 (ancestor) • 子孫 (descendant) • 父親 (parent) • 孩子 (child) • 兄弟 (sibling) • 終端節點 (terminal node) • 內部節點 (internal node) • 階級 (degree) • 層次 (level) • 高度 (height) 或深度 (depth)

  14. 13-5-1 二元樹 對高度為h的二元樹來說,全部存滿的話,總共有20 + 21 + … + 2h-1 = 2h - 1個節點。

  15. 中序追蹤 void inorder(tree_pointer ptr) { if (ptr){ inorder(ptr->lchild); printf(“%d”, ptr->data); inorder(ptr->rchild); } } 圖10.15(b) 的中序追蹤的結果為DBGEHACFI。

  16. 前序追蹤 void preorder(tree_pointer ptr) { if (ptr){ printf(“%d”, ptr->data); preorder(ptr->lchild); preorder(ptr->rchild); } } 圖10.15(b) 的前序追蹤的結果為ABDEGHCFI。

  17. 後序追蹤 void postorder(tree_pointer ptr) { if (ptr){ postorder(ptr->lchild); postorder(ptr->rchild); printf(“%d”, ptr->data); } } 圖10.15(b) 的後序追蹤的結果為DGHEBIFCA。

  18. 13-5-2 二元搜尋樹 它必須滿足下列條件: • 每個節點包含唯一的鍵 (key)。 • 左右子樹亦為二元搜尋樹。 • 左子樹的鍵必須小於其樹根的鍵,右子樹的鍵必須大於其樹根的鍵。

  19. 13-6搜尋 13-6-1 循序搜尋

  20. 13-6-2 二元搜尋

  21. 13-7 排序 13-7-1 插入排序

  22. 13-7-2 氣泡排序

  23. 13-7-3 快速排序

More Related