資料結構 優點 缺點 1 陣列 (Array) 沒有額外變量 (例head, next,...) 運作/操作較簡單 更新資料時,若要保持順序,需要移動較大量資料 靜態結構Static (宣告時已決定了陣列元素多少,不能在程式執行期間增減元素) 2 隊列Queue (FIFO) 容易更新 加入enqueue: 隊尾tail 移除dequeue: 隊首head 需要額外變量head / tail 3 堆疊Stack (LIFO) 容易操作 加入Push移除Pop皆在頂部stack top進行 需要額外變量top 4 鏈表Linked List 加新或移除資料時,只需改動少量資料,仍能保持順序 動態結構Dynamic (程式執行期間,可隨意增減元素) 需要額外變量head, next 運作/操作較複雜(搜尋、更新) 2D Array: 98Queen, 00, 06, 08, 09 Stack 05, 06 LList: 94, 07, 08, 09 Queue
#define N 100 1 Linear Ordered List (Array) char List [N] [10]; 2 Queue (FIFO) char Queue [N] [10]; int Head, Tail; Circular Queue Priority Queue 3 Stack (LIFO) char Stack [N] [10]; int Top; 4 Linked List char LList [N] [10]; int Next [N]; int Head; Doubly Linked Lists 5 Binary Tree 6 DiGraph 7 Heap 8 Hash Table
http://www.apsu.edu/myersb2/linked_list_animation.htm http://www.cs.stir.ac.uk/~mew/dissertation/ http://www.apl.jhu.edu/Classes/605202/felikson/lectures/L3/L3.html http://www.eecg.toronto.edu/~jayar/courses/aps105S/quizzes/quiz2b/node2.html http://www.theparticle.com/javadata2.html Data Structure Advantages Disadvantages 1 Linear Ordered List (Array) No additional storage is required Simple in operation Large overhead for updating (i.e. shifting of elements up or down the list) Static (elements cannot be added at run-time) 2 Queue (FIFO) Easy to update Enqueue at the tail of Queue Dequeue at the head of Queue Additional storage is required i.e. Head / Tail 3 Stack (LIFO) Push and Pop operation are always performed at the Stack Top i.e. Top 4 Linked List Insertion and Deletion are easier than those of a Linear List Dynamic (nodes can be added or removed at run-time) i.e. Head, Link to next node More complex algorithm is required for searching and updating is used