
练习
lhao_cn
懒人
展开
-
练习——LinkedList
package Practice;import java.util.Iterator;public class MyLinkedList implements Iterable{ Value head; int currentSize; public MyLinkedList() { head=new Value(null); curr原创 2016-12-14 13:38:38 · 388 阅读 · 0 评论 -
【练习】从一组数字中找出最大的几个,用堆完成
从一组数字中找出最大的几个,例如从n个数字中找出最大的k个,最容易想到的方法是首先对这n个数字进行从小到大的排序,然后选出前面的k个数字就行了,快速排序的平均时间复杂度是O(nlogn)。不过,在有些面试题里面会有这样一个条件: n非常大,以至于无法将这n个数一次性全部读入内存。这种时候可以用大顶堆来完成这个题目,如果形象的用完全二叉树来想象堆的样子的话,大顶堆中满足“任意一个结点中的值,都大于其原创 2017-03-04 15:25:20 · 3815 阅读 · 1 评论 -
【练习】最长公共子序列
使用动态规划找出2个字符串的最长公共子序列package com.prac;/* * 计算最长公共子序列的长度,并返回该最长公共子序列 */public class LongestCommonSubStr { /* * map用来记录最长公共子序列的长度 */ public static int findLCS(char[] str1,char[] str原创 2017-01-26 15:31:16 · 423 阅读 · 0 评论 -
【练习】在二叉树中找出和为某个值的一条路径
二叉树中节点中只包含正整数值。 使用递归的方式实现,用一个双端队列保存已经经过的节点。到达一个节点的时候,比较当前的和再加上当前节点值是否等于目标值,若等于则输出已经经过的节点和当前节点;若不等于,则将当前节点追加到队列的尾部,再前往当前节点的子节点。import java.util.LinkedList;public class FindSum { //树中的节点类原创 2017-01-25 15:58:10 · 282 阅读 · 0 评论 -
练习——堆排序
package methods;public class HeapSort { public static void moveBigger2Top(int[] x,int i,int scope) { int father=i; while(father <= scope) { int leftSon=father*原创 2016-12-14 13:43:45 · 324 阅读 · 0 评论 -
练习——快速排序
package methods;public class QuickSort { public static void sort(int[] x,int start,int end) { int i=start,j=end; while(i<j) { while(i<j && x[i]<=x[j])原创 2016-12-14 13:43:11 · 284 阅读 · 0 评论 -
练习——合并排序
package methods;public class MergeSort { public static int[] sort(int[] x,int start,int end) { if(start == end) { int[] ret=new int[1]; ret[0]=x[start];原创 2016-12-14 13:42:47 · 287 阅读 · 0 评论 -
练习——冒泡排序
package methods;public class BubbleSort { public static void sort(int[] arr) { int length=arr.length; for(int i=0;i<length;i++) { boolean changed=false;原创 2016-12-14 13:42:13 · 437 阅读 · 0 评论 -
练习——HashMap
package Practice;import java.util.Iterator;public class MyHashMap { int tableSize; MyArrayList table; public MyHashMap(int tableSize) { this.tableSize=tableSize; table=n原创 2016-12-14 13:40:24 · 521 阅读 · 0 评论 -
练习——ArrayList
练习实现一个简单的ArrayList原创 2016-12-14 13:36:50 · 398 阅读 · 0 评论 -
Java写文件乱码问题
写入文件的例子:public static void main(String[] args) throws IOException { // TODO Auto-generated method stub File file = new File("/home/k/a"); OutputStreamWriter osw=new OutputStreamW原创 2017-03-31 14:47:52 · 316 阅读 · 0 评论