数据结构
ou叮当
这个作者很懒,什么都没留下…
展开
-
用最大堆实现优先队列(c++)
关于最大堆,最小堆的概念这里不再介绍。#include <iostream> #include <vector> using namespace std;template<typename T> class PriorityQueue { private: vector<T> v; int size; const static int init原创 2017-08-18 00:42:11 · 6919 阅读 · 0 评论 -
简单的闭散列(hashtable)实现(c++)
#include <iostream> #include <algorithm> #include <string>extern "C" { #include <ctype.h> #include <string.h> }template <typename T> class HashTable { private: std::list< std::pair<std::str原创 2017-08-14 13:18:30 · 6014 阅读 · 0 评论 -
跳跃表的实现(c++)
这里不介绍跳跃表是什么东西了,如果没有推导过跳跃表或者索性不知道跳跃表是什么东西请看麻省理工大学公开课 算法导论 跳跃表。 代码中有一个容易误解的地方解释一下,randomLevel模拟抛硬币的过程比较不太直观,在插入过程中一个节点上升的次数实际上等价于连续出现“正面”的次数,所以我们直接一次性算出来,而不是每插完一个节点抛一次硬币,这样方便在进行实际插入之前进行一些检查 本代码原创 2017-08-28 00:27:36 · 7376 阅读 · 0 评论 -
java.util.NoSuchElementException
在一个android项目上用到List来作为RTP包的队列,一个线程入队一个线程出队,频率比较高,跑几秒钟就挂了,异常:java.util.NoSuchElementException这是什么原因呢,原因是一开始我就认为java的书结构是线程安全的,但默认情况下并不是这样的,有一部分数据结构并不是线程安全的,所以我们得在构造的时候用线程安全的版本:Collections.synchronizedLi原创 2017-12-13 22:04:57 · 446 阅读 · 0 评论 -
protocol buffers c语言的使用
以下源码示例来源于https://github.com/protobuf-c/protobuf-c/wiki/Examples 定义消息message AMessage { required int32 a=1; optional int32 b=2; }安装protobuf-c我们需要把proto文件编译成c源码,才能在代码中使用,所以需要用到官方的编译工具sudo apt-get原创 2017-11-27 16:28:08 · 4805 阅读 · 0 评论