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
| 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
| /** | |
| * 栈的特点是后进先出,新的元素在栈顶,出栈也是从栈顶出。 | |
| * 栈存放的是一个个节点,每个节点存放一个对象的引用,和一个链接。 | |
| * 这个链接指向下一个节点或者 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 ResizingArrayStack<Item> implements Iterable<Item>{ | |
| private Item a[]; | |
| // 元素个数 | |
| private int N; |
NewerOlder