ADT 陣列在資料結構中的體現


基本概念

ADT 表示抽象資料型別。

陣列被定義為 ADT,因為它們能夠按相同的順序儲存連續的元素。它們允許

透過索引或位置訪問特定元素。

它們是抽象的,因為它們可以是字串、整數或人員

int[] arrA = new int[1];
String[] arrB = new String[1];
Person[] arrC = new Person[3]; // where Person is treated as a defined class

優勢

  • 快速隨機訪問專案或元素。
  • 非常省記憶體,除了儲存內容所需的記憶體外,幾乎不需要其他記憶體。

劣勢

  • 插入和刪除元素很慢
  • 建立陣列時必須知道陣列的大小並且是固定的(靜態)

ADT 列表的基於陣列的實現

Public class ListArrayBased implementsListInterface {
   private static final int MAX_LIST1 = 50;
   private Object items1[];
   // an array of list items
   privateint numItems1;
   // number of items in list
   publicListArrayBased() {
      items1 = new Object[MAX_LIST1];
      numItems1 = 0;
   } // end default constructor
}


更新時間:08-Jan-2020

7K+ 瀏覽量

開啟你的 事業

完成課程後獲得認證

立即開始
廣告