上一页 1 2 3 4 5 6 ··· 15 下一页
摘要: 分治算法:把一个大问题分解为两个相对较小的问题,分别解决每一个小问题,对两个小问题的处理方式也一样:分解为两个更小的问题,并解决它们这个过程一直持续下去直到达到易于求解的基值情况,就不用继续分解下去了二分查找是分治算法的一个实例循环二分查找public class BinarySearch { private int[] data; public BinarySearch(int[] data){ this.data = data; } public int search(int target){ int min = 0; int max = data.length - 1; in... 阅读全文
posted @ 2014-04-09 15:50 心意合一 阅读(1536) 评论(0) 推荐(0) 编辑
摘要: 对一个包含n个字母的单词进行全排列:1,对该单词右边n-1个字母进行全排列2,轮换所有字母(所有字母左移一位,最左边的字母移动至最右边)3,以上步骤重复n次(以保证该单词的所有字母都曾经处于第一位)public class FullPermutation { private char[] chars; private int length; public FullPermutation(String str){ chars = str.toCharArray(); length = chars.length; } public void permutation(int num){ i... 阅读全文
posted @ 2014-04-09 14:34 心意合一 阅读(464) 评论(0) 推荐(0) 编辑
摘要: public class DoublyLinkList { private class Data{ private Object obj; private Data left = null; private Data right = null; Data(Object obj){ this.obj = obj; } } private Data first = null; private Data last = null; public void insertFirst(Object obj){ Data data = new Data(obj); if(first ... 阅读全文
posted @ 2014-04-03 22:42 心意合一 阅读(195) 评论(0) 推荐(0) 编辑
摘要: 单链表: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. 阅读全文
posted @ 2014-03-31 23:45 心意合一 阅读(217) 评论(0) 推荐(0) 编辑
摘要: 优先级队列数组实现: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 阅读全文
posted @ 2014-03-31 14:40 心意合一 阅读(422) 评论(0) 推荐(0) 编辑
摘要: 队列数组实现:队列长度有限,但是考虑到平时一般都使用有界队列,这应该也不算是个缺点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... 阅读全文
posted @ 2014-03-31 11:28 心意合一 阅读(635) 评论(0) 推荐(0) 编辑
摘要: 栈数组实现一:优点:入栈和出栈速度快,缺点:长度有限(有时候这也不能算是个缺点)public class Stack { private int top = -1; private Object[] objs; public Stack(int capacity) throws Exception{ if(capacity top: | "); for(int i = 0 ; i top: | 1 | 2 | 2bottom -> top: | 1 | bottom -> top: | 1 | 99 | Exception in thread "main&quo 阅读全文
posted @ 2014-03-30 20:25 心意合一 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 长度为N的数组升序排序一,冒泡排序public class BubbleSort { private double[] data; public BubbleSort(double[] data) { this.data = data; } public void sort(){ for(int p = data.length - 1 ; p > 0 ; p--){ for(int i = 0 ; i data[i+1] ){ double tmp = data[i]; data[i] = data[i+1]; data[i+1] = tmp; } ... 阅读全文
posted @ 2014-03-30 11:50 心意合一 阅读(199) 评论(0) 推荐(0) 编辑
摘要: Linux服务器上,将本地编译好的文件上传后,Tomcat启动时报错:Exception in thread "Thread-2" java.lang.ClassFormatError: Illegal UTF8 string in constant pool in class file Server/Request at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) a... 阅读全文
posted @ 2014-03-26 09:51 心意合一 阅读(1829) 评论(0) 推荐(1) 编辑
摘要: Distribution为Fedora 19方式一(重启后失效,需root权限):hostname 新主机名[root@promote hadoop]# hostnamepromote.cache-dns.local[root@promote hadoop]# hostname fedora[root@promote hadoop]# hostnamefedora方式二(重启后依然生效,需root权限):网上有很多人说只要修改/etc/sysconfig/network文件,在文件中添加如下2行即可:[root@promote sysconfig]# cat /etc/sysconfig/ne 阅读全文
posted @ 2014-03-04 22:03 心意合一 阅读(310) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 15 下一页