⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ascendinglistofint.java

📁 Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套 代码
💻 JAVA
字号:
// Figure 11.17/** CLass Invariant *		An AscendingListOfInt contains Integers sorted in ascending order.  */public class AscendingListOfInt extends SimpleList<Integer> {	/**	post:	this is empty 	 *			and  iterator == 0		 */	public AscendingListOfInt()  {		super();	}	/**	post:	this list == this@pre with k inserted (note that the	 *				sort property from the class invariant is maintained)	 *			and  iterator is positioned immediately after	 *				the newly inserted k 	 */	public boolean add(Integer k)  {		boolean  found;		int tempInt = 0;		reset();		found = false;		while ( !found  &&  hasNext() )  {			tempInt = next();			found = (k <= tempInt);		}		if (!found) {			super.add(k);		} else {			remove();			super.add(k);			super.add(tempInt);		}		return true;   // because add is a boolean method	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -