
算法
传葱
Talk is cheap, show me the code.
展开
-
使用归并排序计算逆序对个数
使用归并排序计算逆序对个数 给出一个数组 arr[8] = {8,7,4,5,4,10,2,1},比如8,7就是逆序,使用归并排序找出逆序对的个数,代码如下: #include <iostream>int nixu = 0;//定义一个全局变量来存储逆序对的个数 using namespace std; template <typename T> void __merge(T arr原创 2017-10-27 14:30:33 · 1835 阅读 · 0 评论 -
快速排序搜索一个数组中第N大的数字
#include <iostream> #include "SortTestHelper.h"using namespace std; template <typename T> int __partition(T arr[], int l, int r) { swap( arr[l], arr[rand()%(r-l+1) + l] ); T v = arr[l]; int原创 2017-10-27 16:56:06 · 1380 阅读 · 0 评论 -
KMP算法
什么是KMP算法?解决字符串匹配的效率问题。 https://www.youtube.com/watch?v=GTJr8OvyEVQpublic class SubstringSearch { //重点在这个方法这里,每次pattern匹配到第j个字符的时候发现无法匹配,不会直接跳转到index = 0的字符,而是和它有相同前缀的字符那边,具体可以看上面视频,这个讲的不错。思考一下传统的字原创 2017-12-15 13:07:52 · 273 阅读 · 1 评论 -
Map中的hash()分析
https://juejin.im/post/5ab99afff265da23a2291dee转载 2018-03-28 17:43:14 · 236 阅读 · 0 评论