S SmartDocs
Série: Angelia java 26 linhas · Atualizado 2026-09-27

SimpleList.java

Angelia/Java/Week_6_7/code/02_adt_interfaces/SimpleList.java

/**
 * 最經典的 ADT:List(串列)。
 *
 * 串列是「有順序」的集合(有第一個、第二個……),允許重複,且大小可以改變
 * ——「大小可變」正是串列與陣列最大的差別。
 *
 * 注意:這裡的元素型別是 Object(任何物件都能放);
 * 第 7 章會用「泛型」把它升級成 SimpleList<T>。
 */
public interface SimpleList {

    /** @return 串列中元素的個數 */
    int size();

    /**
     * @param index 前置條件:0 <= index < size()
     * @return 第 index 個元素(從 0 起算)
     */
    Object get(int index);

    /** 把 o 加到串列尾端。後置條件:size() 增加 1 */
    void add(Object o);

    /** 移除第一個與 o 相等(equals)的元素;若不存在則什麼都不做。 */
    void remove(Object o);
}

Artigos relacionados