# 9/29 K速記 資料結構 * ArrayList 的插入及刪除 都須連續搬移 效能不佳 * Linked-List * 每一筆資料 同時儲存下一筆的位置,插入以及刪除都可有效率進行 * 取得資料 效率差 但刪除及插入效率較好 * ArrayList較常用 ```java= public class LinkedList{ private static class Node{ private int data; private Node next; } private Node root; private int count; public LinkedList(){ root = new Node(); count = 0; } public void add(int data){ Node tmp = root;//暫存變數 while(tmp.next != null ){ tmp = tmp.next; } tmp.next = new Node(data); } public int get (int index){ if(index <0 || index >= count) { return -1; } } } ``` ## Design patern 迭代式 Iterator * arraylist vs linklist * 將兩種都加入Iterator 介面 實現 判定 hasNext() 及 Next() ```java= for(a:al){ //取出al內每一個數值 暫存名稱為a 再對a進行action } ```