📄 ascendinglist.java
字号:
// Figure 11.18/** CLass Invariant * An AscendingListOfInt contains objects sorted in ascending order. */public class AscendingList<ItemType extends Comparable> extends SimpleList<ItemType> { /** post: this is empty * and iterator == 0 */ public AscendingList() { super(); } /** post: this list == this@pre with z inserted (note that the * sort property from the class invariant is maintained) * and iterator is positioned immediately after * the newly inserted z */ public boolean add(ItemType z) { boolean found; ItemType temp = null; reset(); found = false; while ( !found && hasNext() ) { temp = next(); found = (z.compareTo( temp ) <= 0); } if (!found) { super.add(z); } else { remove(); super.add(z); super.add(temp); } return true; // because add is a boolean method }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -