This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Iterator; | |
import java.util.Scanner; | |
//自动修改大小、内部用数组实现的栈 | |
public class ResizingArrayStack<Item> implements Iterable<Item>{ | |
private Item a[]; | |
// 元素个数 | |
private int N; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 栈的特点是后进先出,新的元素在栈顶,出栈也是从栈顶出。 | |
* 栈存放的是一个个节点,每个节点存放一个对象的引用,和一个链接。 | |
* 这个链接指向下一个节点或者 null。 | |
* 栈中的 first 变量链接第一个节点。 | |
*/ | |
import java.util.Iterator; | |
import java.util.Scanner; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Iterator; | |
import java.util.Scanner; | |
public class LinkQueue<Item> implements Iterable<Item>{ | |
// 分别指向队头、队尾 | |
private Node first; | |
private Node last; | |
// 队列中元素个数 | |
private int N; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Stack<String>[] a = (Stack<String>[]) new Stack[N]; | |
虽然 Stack 不是泛型类,但是它含有一个泛型参数。 | |
所以下面这种方式会报错。 | |
LinkStack<String>[] b = new LinkStack<String>[4]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Item[] a = (Item[]) new Object[N]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Stack<Integer> stack = new Stack<Integer>(); | |
while(N > 0) { | |
stack.push(N % 2); | |
N = N / 2; | |
} | |
for(int d : stack) { | |
System.out.print(d); | |
} | |
System.out.println(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* void deleteLast() 删除最后一个元素 | |
* void delete(int k) 删除第 k 个元素 | |
* boolean find(LinkedList list, String key) 查找链表中是否存在某个结点的值域为 key | |
* void removeAfter(Node node) 删除该结点的后续结点 | |
* void insertAfter(Node node1, Node node2) 将第二个结点放在第一个结点后面 | |
* void remove(LinkedList list, String key) 删除所有值为 key 的结点 | |
* int max(LinkedList first) 接收一个首结点,返回值最大的结点的值,为空返回 0 | |
* int max(LinkedList first) 用递归解决 | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//内部类依赖于外部类,所以要先创建外部类对象 | |
//第一种方式: | |
Outter outter = new Outter(); | |
Outter.Inner inner = outter.new Inner(); //必须通过Outter对象来创建 | |
//第二种方式: | |
Outter.Inner inner1 = outter.getInnerInstance(); | |
//如果外部类是泛型类,可以这么写 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//使用之前: | |
//项目 -> 添加引用 -> 搜索 System.web 添加 | |
string str = System.Web.HttpUtility.UrlEncode("机械键盘", System.Text.Encoding.GetEncoding("GB2312")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.查看帮助ToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.D5 | Keys.Control; |
OlderNewer