随笔分类 - 数据结构和算法
摘要:package main import ( "errors" "math/rand" ) type CompareResult int // TODO 目前尚未实现并发安全,待办 const ( // 跳表节点key的比较回调函数返回值 -1:left<right;0:left==right;1:l
阅读全文
摘要:代码如下: 1 package main 2 3 import ( 4 "fmt" 5 ) 6 7 func pivot(arr []int, begin int, end int) int { 8 end-- 9 temp := arr[begin] 10 // 为减小最坏情况发生的几率,可以在b
阅读全文
摘要:typedef union bigSmallEnd{ unsigned short a; unsigned char b[2]; }BSE; void testBSE() { BSE test; test.a = 0x0102; if (test.b[0] == (unsigned char) 0x
阅读全文
摘要:非优化版本 /* * NQueens.h * * Created on: 2020年3月2日 * Author: LuYonglei */ #ifndef SRC_NQUEENS_H_ #define SRC_NQUEENS_H_ #include <iostream> using namespac
阅读全文
摘要:头文件 /* * MemoryManage.h * * Created on: 2020年2月22日 * Author: LuYonglei */ #ifndef SRC_MEMORYMANAGE_H_ #define SRC_MEMORYMANAGE_H_ #include <stdlib.h>
阅读全文
摘要:/* * UnionFind.h * 有两种实现方式,QuickFind和QuickUnion * QuickFind: * 查找O(1) * 合并O(n) * QuickUnion:(建议使用) * 查找O(logn)可优化至O(a(n)),a(n)<5 * 合并O(logn)可优化至O(a(n)
阅读全文
摘要:/* * UnionFind.h * 有两种实现方式,QuickFind和QuickUnion * QuickFind: * 查找O(1) * 合并O(n) * QuickUnion:(建议使用) * 查找O(logn)可优化至O(a(n)),a(n)<5 * 合并O(logn)可优化至O(a(n)
阅读全文
摘要:/* * UnionFind.h * 有两种实现方式,QuickFind和QuickUnion * QuickFind: * 查找O(1) * 合并O(n) * QuickUnion:(建议使用) * 查找O(logn)可优化至O(a(n)),a(n)<5 * 合并O(logn)可优化至O(a(n)
阅读全文
摘要:冒泡排序 /* * BubbleSort.h * 冒泡排序 * Created on: 2020年2月10日 * Author: LuYonglei */ #ifndef SRC_BUBBLESORT_H_ #define SRC_BUBBLESORT_H_ #include <vector> us
阅读全文
摘要:/* * QuickSort.h * 快速排序(将每一个元素转换为轴点元素) * Created on: 2020年2月12日 * Author: LuYonglei */ #ifndef SRC_QUICKSORT_H_ #define SRC_QUICKSORT_H_ #include <vec
阅读全文
摘要:/* * HeapSort.h * 堆排序 * Created on: 2020年2月10日 * Author: LuYonglei */ #ifndef SRC_HEAPSORT_H_ #define SRC_HEAPSORT_H_ #include <vector> using namespac
阅读全文
摘要:/* * MergeSort.h * 归并排序 * Created on: 2020年2月12日 * Author: LuYonglei */ #ifndef SRC_MERGESORT_H_ #define SRC_MERGESORT_H_ #include <vector> using name
阅读全文
摘要:BinaryHeap源码实现 /* * BinaryHeap.h * 二叉堆(完全二叉堆) * Created on: 2020年2月3日 * Author: LuYonglei */ #ifndef SRC_BINARYHEAP_H_ #define SRC_BINARYHEAP_H_ #incl
阅读全文
摘要:AVLTree源码实现 /* * BinarySearchTree.h * 1. 添加元素时需自己做判断元素是否合法 * 3. 本代码实现的AVL树没有统一旋转操作,采用分情况讨论LL,LR,RR,RL来进行树的平衡 * Created on: 2020年1月29日 * Author: LuYong
阅读全文
摘要:RBTree源码实现
/*
* BinarySearchTree.h
* 添加元素时需自己做判断元素是否合法
* Created on: 2020年1月29日
* Author: LuYonglei
*/
阅读全文
摘要:/*
* BinarySearchTree.h
* 添加元素时需自己做判断元素是否合法
* Created on: 2020年1月29日
* Author: LuYonglei
*/
#ifndef SRC_BINARYSEARCHTREE_H_
#define SRC_BINARYSEARCHTREE_H_
#include
阅读全文
摘要:/*
* BinarySearchTree.h
* 1. 添加元素时需自己做判断元素是否合法
* 2. 除层序遍历外,本源代码均采用递归遍历,若要减少栈的消耗,应该实现迭代遍历
* 3. 本代码实现的AVL树有统一旋转操作,不用分情况讨论LL,LR,RR,RL来进行树的平衡
* 统一旋转操作有特殊优化版本和统一接口版本,本代码保留了统一接口的源码,但是采用的是特殊优化版本
* Created on: 2020年1月29日
* Author: LuYonglei
*/
阅读全文
摘要:/*
* BinarySearchTree.h
* 1. 添加元素时需自己做判断元素是否合法
* 2. 除层序遍历外,本源代码均采用递归遍历,若要减少栈的消耗,应该实现迭代遍历
* 3. 本代码实现的AVL树没有统一旋转操作,采用分情况讨论LL,LR,RR,RL来进行树的平衡
* Created on: 2020年1月29日
* Author: LuYonglei
*/
阅读全文

浙公网安备 33010602011771号