下压(LIFO)栈:可以动态调整数组大小的实现 import java.util.Iterator; public class ResizingArrayStack<Item> implements Iterable<Item> { private int N = 0; private Item[] a = (Item[]) new Object[1]; public boolean isEmpty() { return N == 0; } public int size() {…
希尔排序思想:使数组中随意间隔为h的元素都是有序的. 希尔排序是插入排序的优化.先对数组局部进行排序,最后再使用插入排序将部分有序的数组排序. 代码例如以下: /** * * @author seabear * */ public class ShellSort { public static void sort(Comparable[] a) { int N = a.length; int h = 1; while(h < N/2) { h = 4 * h + 1; } while(h >=…
软件:DrJava 参考书:算法(第四版) 章节:2.4优先队列(以下截图是算法配套视频所讲内容截图) 1:API 与初级实现 2:堆得定义 3:堆排序 4:事件驱动的仿真 优先队列最重要的操作就是删除最大元素和插入元素,我们会把精力集中在他们身上.删除最大元素的方法名为delMax(),插入元素的方法名为insert().…
软件:DrJava 参考书:算法(第四版) 章节:2.3快速排序(以下截图是算法配套视频所讲内容截图) 1:快速排序 2:…
Immutable Strings Objects of the String class are immutable. If you examine the JDK documentation for the String class, you’ll see that every method in the class that appears to modify a String actually creates and returns a brand new String object c…
At the lowest level, data in Java is manipulated using operators Using Java Operators An operator takes one or more argument and produces a new value. The arguements are in a different form than ordinary method calls, but the effect is the same. + :…
---恢复内容开始--- Both C++ and Java are hybird languages. A hybird language allow multiple programming styles The reason C++ is hybird is to support backward compatibility with the C langguage (a superset of the C language) The Java language assumes that…
Runtime type information (RTTI) allow you to discover and use type information while a program is running This take two forms: 1. "traditional" RTTI, which assumes that you have all the types available at compile time, 2. the reflection mechanis…
The ideal time to catch an error is at compile time, before you even try to run the program. However, not all errors can be detected at compile time. To create a robust system, each component must be robust. By providing a consistent error-reporting…
To solve the general programming problem, you need to create any number of objects, anytime, anywhere. So you can't rely on creating a named reference to hold each one of your objects. Java has several ways to hold objects: 1. the compiler-supported…