数据结构
栈stack
实现:链表:表的顶端LIFO,插入push,弹出pop
数组:空栈topOfStack初始化-1;插入,topOfStack加1,theArray[topOfStack]=x;弹出,返回值theArray[topOfStack], topOfStack减1
1.消除尾递归:将代码放到一个while循环中,用每个方法参数的一次赋值代替递归调用
2.中缀转后缀:操作数放到output中。操作符放到栈中,当前操作符放入栈之前,只要它优先级小于或等于栈顶操作符,栈顶操作符被弹出到output中,它被压入栈中。左括号优先级最高放入栈中,重复上述,直到读到右括号,将栈元素中的操作符直到左括号弹出到output,左右括号不放入output中。输入为空,将栈中操作符全部弹出到output。
队列queue
实现:链表&数组,enqueue队尾入队,dequeue队头出队
数组实现:数组theArray,两端位置front和back,元素个数currentSize
元素x入队: currentSize和back加1,theArray[back]=x
元素出队:返回值theArray[front], currentSize减1,front加1
循环数组:只要front或back到达数组尾端回绕到对头。
程序设计基础
Enumeration接口:使用在Vector和Propertie,这种传统接口已被迭代器取代,
boolean hasMoreElements( ) 测试此枚举是否包含更多的元素;
Object nextElement( )如果此枚举对象至少还有一个可提供的元素,则返回此枚举的下一个元素
String类:不可改变,管理者
length() | 静态方法format()创建可复用的格式化字符串 |
'+'操作符来连接字符串 | int compareTo() int compareToIgnoreCase() |
char charAt(int index) | boolean endsWith(String suffix) boolean equalsIgnoreCase(String anotherString) String[] split(String regex) |
boolean equals() boolean equalsIgnoreCase() |
int indexOf()、int lastIndexOf() |
String replace(char oldChar, char newChar) | String replaceAll(String regex, String replacement) 使用给定的 replacement 替换此字符串所有匹配给定的正则表达式的子字符串 |
String[] split(String regex) | String substring(int beginIndex, int endIndex) |
char[] toCharArray() void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) |
String toLowerCase() String toUpperCase() |
String fs;
fs = String.format("The value of the float variable is " + "%f, while the value of the integer "
+ "variable is %d, and the string " + "is %s", floatVar, intVar, stringVar);
System.out.println(fs);
StringBuffer和StringBuilder类:对象能够被多次的修改,并且不产生新的未使用对象;单任务访问,StringBuilder有速度优势;多任务访问,在应用程序要求线程安全的情况下,则必须使用StringBuffer类
public StringBuffer append(String s) 将指定的字符串追加到此字符序列。 | </