?? bag.java
字號:
/** Bag Class * Author: David D. Riley * Date: June, 2004 * * class invariant * A Bag object ... * * is a container of zero or more other objects * * is capable of storing anything that conforms to Object */public class Bag<ItemType> extends SimpleList<ItemType> { /** post: this is an empty bag (i.e. size() == 0) */ public Bag() { super(); } /** post: result == number of items in this Bag * note: this method is inherited */// public int size() /** post: this == this@pre with some z inserted * and size() == size()@pre + 1 * note: this method is inherited */// public void add(ItemType z) /** pre: count() > 0 <br> * post: this == this@pre with some item removed * and size() == size()@pre - 1 * note: this method is inherited */// public void remove() /** pre: size() > 0 * post: result == one of the items from this Bag */ public ItemType item() { int skipCount; super.reset(); // the following code randomizes which item is returned. skipCount = (int) (Math.random() * size()); for ( ; skipCount>0; skipCount--) { super.next(); } return super.next(); } public String toString() { String str = ""; super.reset(); while (super.hasNext()) { str = str + " " + super.next().toString(); } return str; } // The methods below are overridden to disable them. /** post: this method is disabled */ public void reset() { } /** post: this method is disabled */ public ItemType next() { return null; } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -