摘要:
单链表:insertFirst:在表头插入一个新的链接点,时间复杂度为O(1)deleteFirst:删除表头的链接点,时间复杂度为O(1)有了这两个方法,就可以用单链表来实现一个栈了,见http://blog.csdn.net/a19881029/article/details/22579759find:查找包含指定关键字的链接点,由于需要遍历查找,平均需要查找N/2次,即O(N)remove:删除包含指定关键字的链接点,由于需要遍历查找,平均需要查找N/2次,即O(N)public class LinkedList { private class Data{ private Object. 阅读全文
摘要:
优先级队列数组实现:public class PriorityQueue { private int[] data; private int size; public PriorityQueue(int size){ data = new int[size]; this.size = 0; } public void push(int toInsert) throws Exception{ if(size == data.length) throw new Exception("Queue is full!"); if(size == 0){ data[0] = toIns 阅读全文
摘要:
队列数组实现:队列长度有限,但是考虑到平时一般都使用有界队列,这应该也不算是个缺点public class Queue { private Object[] objs; private int head; private int end; private int size; public Queue(int size){ objs = new Object[size]; this.head = 0; this.end = -1; this.size = 0; } public void push(Object obj) throws Exception{ if(this.size... 阅读全文