数据结构与算法
文章平均质量分 91
ok0011
这个作者很懒,什么都没留下…
展开
-
二叉树序列化和反序列化
import java.util.Arrays;import java.util.Iterator;import java.util.LinkedList;import java.util.List;class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { ...原创 2020-04-15 16:56:53 · 221 阅读 · 0 评论 -
二叉搜索树查找第K小的元素
class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; }}public class Solution { /** * 查找第K小的元素 */ public int kthSmalles...原创 2020-04-12 22:21:37 · 561 阅读 · 0 评论 -
二叉树求两个节点最近公共祖先
class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; }}public class Solution { /** * 求2个节点最近公共祖先 */ public TreeNode lo...原创 2020-04-12 22:19:02 · 260 阅读 · 0 评论 -
简单的LFU Cache实现
import java.util.HashMap;import java.util.Map;import java.util.TreeMap;class LFUCache { static class Node { private int key; private int value; private int frequency; ...原创 2020-04-05 18:41:15 · 403 阅读 · 0 评论 -
简单的Trie前缀树实现
import java.util.LinkedList;import java.util.List;class TrieNode { List<TrieNode> children = new LinkedList<>(); boolean isEnd; char item = ' '; public TrieNode() { ...原创 2019-12-26 11:01:05 · 159 阅读 · 0 评论 -
简单的LRU Cache实现
class LRUCache { public static class Node { public int key; public int value; public Node pre; public Node next; public Node(int key, int value) { ...原创 2019-12-26 10:48:36 · 140 阅读 · 0 评论 -
简单的HashMap实现
class MyHashMap { private int sizeOfTable = 1024; private Node[] table = new Node[sizeOfTable]; private class Node { public int key; public int value; public Node...原创 2019-12-26 10:41:52 · 142 阅读 · 0 评论 -
Skip List基本操作
public class SkipList { public int height; public int size; public Random random = new Random(); public Node head = new Node(0, null, true); public static class Node { pu...原创 2019-12-25 14:28:55 · 196 阅读 · 0 评论 -
AVL树基本操作
public class AVLTree { public static class Node { public int data; public int height; public Node left; public Node right; public Node(int data) { ...原创 2019-12-21 21:08:29 · 217 阅读 · 0 评论 -
求图的关键路径
#include <iostream>using namespace std;#define MAXVERTEX 100typedef int infotype;#define NULL 0struct ArcNode{ int adjvex; infotype *info; ArcNode *nextarc;};struct VerNode{ int原创 2015-06-16 22:56:07 · 869 阅读 · 0 评论 -
求图中任意两个顶点间的最短路径
#include <iostream>using namespace std;const int MAXVERTEXNUM = 100;const int MAX_WEIGHT = 32767;struct MGraph{ char vers[MAXVERTEXNUM]; int edges[MAXVERTEXNUM][MAXVERTEXNUM]; int n,原创 2015-06-16 22:54:53 · 3498 阅读 · 0 评论 -
并查集求最近公共祖先
package algorithm;import java.io.BufferedOutputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.PrintWriter;import java.util.ArrayList;import java.util.Ha原创 2015-06-16 15:06:11 · 494 阅读 · 0 评论 -
选择排序
package sort;public class SelectionSort1 { public static void SelectionSort(int array[]){ for(int i = 0;i < array.length - 1;i++){ int min = i; for(int j = i + 1;j <原创 2015-06-16 15:04:09 · 297 阅读 · 0 评论 -
冒泡排序
package sort;public class BubbleSort1 { public static void BubbleSort(int array[]){ for(int i = array.length-1;i > 0;i--){ for(int j = 0;j < i;j++){ if(array[j] >原创 2015-06-16 15:03:31 · 272 阅读 · 0 评论 -
kmp bm sunday 字符串查找算法
package algorithm;class Kmp{ public int index(String a, String b){ if(a == null || b == null || a.length() < b.length()) return -1; int temp ; for(int i = 0, j =原创 2015-06-16 15:01:27 · 585 阅读 · 0 评论 -
快速排序
package sort;public class QuickSort1 { public static void QuickSort(int array[],int low,int high){ if(low >= high) return; int i = low; int j = high; int原创 2015-06-16 14:57:58 · 285 阅读 · 0 评论 -
堆排序
package sort;public class HeapSort1 { public static void Heapify(int array[],int length){ for(int i=length/2 ; i >= 0; i-- ){ SiftDown(array,i,length); } } publ原创 2015-06-16 14:55:26 · 285 阅读 · 0 评论 -
树的基本操作
package datastructure;import java.util.ArrayList;import java.util.LinkedList;import java.util.List;import java.util.Queue;import java.util.Stack;class BiTree{ char data; BiTree leftchild;原创 2015-06-16 14:53:27 · 349 阅读 · 0 评论 -
图的最短路径
#include <iostream>using namespace std;const int MAXVERTEXNUM = 100;const int MAX_WEIGHT = 32767;struct MGraph{ char vers[MAXVERTEXNUM]; int edges[MAXVERTEXNUM][MAXVERTEXNUM]; int n,原创 2015-06-16 14:50:28 · 408 阅读 · 0 评论 -
JDK字符串查找算法
public class StringIndex { int indexOf(char[] source, int sourceOffset, int sourceCount, char[] target, int targetOffset, int targetCount, int fromIndex) { if原创 2016-06-07 23:06:45 · 519 阅读 · 0 评论 -
拓扑排序
#include <iostream>using namespace std;#define MAXVERTEX 100#define NULL 0struct ArcNode{ int adjvex; ArcNode *nextarc;};struct VerNode{ int vertex; ArcNode *fistarc;};struct Al原创 2015-06-16 23:06:41 · 288 阅读 · 0 评论 -
哈夫曼编码
#include <iostream>#include <string>#define n 4#define m 2*n-1using namespace std;const int MAX = 100;typedef struct{ int weight; int parent, lchild, rchild;} HuffmanTree;typedef Huffman原创 2015-06-16 23:07:52 · 339 阅读 · 0 评论 -
直接插入排序
import java.util.Arrays;public class InsertSort { public static void insertSort(int[] array){ int i,j,temp; for(i = 1; i < array.length; i++){ if(array[i] < array[i-1]){原创 2016-05-09 12:57:24 · 184 阅读 · 0 评论 -
折半插入排序
import java.util.Arrays;public class BinaryInsertionSort { public static void binaryInsertSort(int[] array){ int i, j, temp, low, high, mid; for(i = 1; i < array.length; i++){原创 2016-05-09 13:13:43 · 191 阅读 · 0 评论 -
快速排序找第k大的数
public class findKMax { public static int findKMaxInteger(int array[],int low,int high, int findK){ int i = low; int j = high; int key = array[i]; while(i < j){原创 2016-05-09 14:55:25 · 935 阅读 · 0 评论 -
二叉搜索数求最近公共祖先
import java.util.ArrayList;import java.util.LinkedList;import java.util.List;import java.util.Stack;class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) {原创 2016-05-22 19:31:01 · 223 阅读 · 0 评论 -
找出二叉树所有到叶子节点的路径
import java.util.*;class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; }}public class Solution { public List<String> binaryTreePaths(Tree原创 2016-06-09 23:21:57 · 1004 阅读 · 0 评论 -
二叉树层次遍历
import java.util.ArrayList;import java.util.LinkedList;import java.util.List;class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } TreeNo原创 2016-06-11 23:35:25 · 237 阅读 · 0 评论 -
判断二叉树是否是平衡二叉树
class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } TreeNode(int x, TreeNode left, TreeNode right) { this.val = x; this.l原创 2016-06-13 00:27:29 · 273 阅读 · 0 评论 -
判断二叉树是否相同,对称
class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; }}public class Solution { public boolean isMirror(TreeNode left, TreeNode right) {原创 2016-06-15 00:06:04 · 303 阅读 · 0 评论 -
二分查找
import java.util.Arrays;public class BinarySearch { public static int binarySearch1(int[] array, int key){ int low = 0; int high = array.length - 1; int mid; while (原创 2016-05-05 23:38:21 · 238 阅读 · 0 评论 -
单链表逆转
public static Node reverse(Node head) { Node curr = head; Node pre = null; while (curr != null) { Node next = curr.next; curr.next = pre; pre = curr; curr = next; }原创 2016-04-27 23:50:53 · 269 阅读 · 0 评论 -
归并排序
public class MergeSort { public static void mergeTwoArray(int[] array, int low, int mid, int high){ int[] temp = new int[array.length]; int k = 0; int i = low; int j原创 2016-04-27 21:14:23 · 172 阅读 · 0 评论 -
用栈实现表达式求值
#include using namespace std;typedef double ElemType;#define maxsize 100typedef struct SN{ ElemType data[maxsize]; int top;} StackNode;StackNode StackInit(){ StackNode s;原创 2015-06-16 23:09:13 · 1719 阅读 · 1 评论 -
图的基本操作
import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;import java.util.LinkedList;import java.util.List;import java.util.Queue;import java.util.Stack;//邻接矩阵class Graph{原创 2015-06-17 16:32:58 · 359 阅读 · 0 评论 -
希尔排序
package sort;public class ShellSort1 { public static void ShellSort(int array[]){ int gap,i,j; for(gap = array.length / 2;gap > 0;gap /= 2){ for(i = gap;i < array.length;原创 2015-06-17 17:28:39 · 278 阅读 · 0 评论 -
双向冒泡排序
package sort;public class CocktailSort1 { public static void Swap(int array[],int i,int j){ int temp = array[i]; array[i] = array[j]; array[j] = temp; } public static原创 2015-06-17 17:29:56 · 290 阅读 · 0 评论 -
二叉排序树的基本操作
package datastructure;class BSTree{ int data; BSTree leftchild; BSTree rightchild;}class BST{ //搜索 public BSTree search(BSTree tree, int key){ if(tree == null)原创 2015-06-18 15:31:37 · 395 阅读 · 0 评论 -
哈夫曼编码与解码
package datastructure;import java.util.Comparator;import java.util.HashMap;import java.util.Map;import java.util.PriorityQueue;import java.util.Queue;class HuffmanTree { char data; HuffmanT原创 2015-06-19 11:10:39 · 656 阅读 · 0 评论 -
堆的基本操作
package datastructure;class Heap{ int[] data; int length;}class HeapOp{ public Heap create(Heap heap){ int n = heap.length; for(int i = (n - 1) / 2; i >= 1; i--)原创 2015-06-19 16:32:30 · 416 阅读 · 0 评论