
算法
u-wind14
坚持到最后才有收获
展开
-
堆排序
package Sort;public class Heap_Sort { static int heap_length ; public static void main(String[] args) { int []a = {16,14,10,8,7,9,3,2,4,1}; int []b = new int [a.length+1];原创 2016-08-31 16:23:57 · 180 阅读 · 0 评论 -
归并排序
package Sort;import java.util.Random;public class Merge_Sort { final static int inf = Integer.MAX_VALUE; public static void main(String[] args) { //初始化数组 int [] a = new int [100原创 2016-08-31 16:25:47 · 204 阅读 · 0 评论 -
插入排序
package Sort;public class Insertion_Sort { //测试数据 public static void main(String[] args) { int [] a = {3,4,5,6,9,1,0,2,7,8}; //排序前 for(int i = 0;i<a.length;i++){原创 2016-08-31 16:22:36 · 209 阅读 · 0 评论 -
广度优先搜索(Breadth First Search,BFS)
广度优先搜索使用队列实现从根节点到子节点扩展,在遍历图中相当于前序遍历Sample In 5 4 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 1 1 4 3Sample Out 7//C代码#include <cstdio>#include <cstring>#include <iostream>using namespace std;st原创 2017-02-03 12:20:27 · 268 阅读 · 0 评论 -
Dijkstra算法(最短路径)
基本思想 每次找到离源点最近的一个顶点,然后以该顶点为中心进行扩展,最终得到源点到其余所有点的最短路径。基本歩骤 将所有顶点分为两部分:已知最短路径的顶点集合P和未知最短路径的顶点集合Q。最开始,已知最短路径的顶点集合P中只有源点一个顶点。这里用book数组来记录哪些点在集合P中。 设置源点S到自己的最短路径为0 即dis[s]=0。若存在有源点能直接到达的顶点i,原创 2017-02-10 18:40:07 · 369 阅读 · 0 评论 -
深度优先搜索(dfs)
给出迷宫地图与宝物地点,找出宝物最短路径?Sample In5 4 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 1 1 4 3Sample Out7import java.util.Scanner;public class Main { static int m,n;//地图大小 static int endX,endY;//搜索地点原创 2017-02-02 21:08:58 · 210 阅读 · 0 评论 -
冒泡排序(Bubble Sort)
package Sort;/** * 算法 * 冒泡排序 * @author lxw * */public class Bubble_Sort { public static void main(String[] args) { int[] arr = {10,2,3,4,3,8,6}; Bubble_sort(arr); for(原创 2017-03-12 10:52:13 · 192 阅读 · 0 评论 -
二分查找
// 非递归写法public static int search(int[] arr,int des){ int left = 0; int right = arr.length - 1;//arr长度-1 while(left<=right){ int mid = (left+right)/2; if(des == arr[mid]){原创 2017-09-21 11:59:47 · 215 阅读 · 0 评论