C 语言库大全 — 容器类库

C 语言没有 STL,但可以通过手动实现或使用第三方库来获得容器功能。
每个容器的详细手动实现见 [[|C语言数据结构教程]]。


手动实现的容器

容器文件核心 API
动态数组动态数组init, push_back, pop_back, get, resize, free
单向链表单向链表push_front, pop_front, insert_after, remove_after, reverse
双向链表双向链表push_back, push_front, pop_back, pop_front, remove, insert_before
push, pop, top, empty(数组 + 链表两种实现)
循环队列循环队列enqueue, dequeue, front, is_full, is_empty
链式队列链式队列enqueue, dequeue, front, is_empty
哈希表(链地址法)链地址法put, get, remove, rehash
哈希表(开放地址法)开放地址法put, get, remove, rehash(线性/二次/双重探测)
二叉搜索树二叉搜索树insert, search, delete, inorder, min
AVL 树AVL树insert, delete, search(自平衡,严格 O(log n))
push, pop, top, heapify(优先队列)
图(邻接表)邻接表add_edge, bfs, dfs(适合稀疏图)
图(邻接矩阵)邻接矩阵add_edge, bfs, dfs(适合稠密图)

第三方 C 容器库

特点链接
uthash纯头文件哈希表,支持增删查https://github.com/troydhanson/uthash
klib纯头文件通用库:khash(哈希), kvec(动态数组), kbtree(B树)https://github.com/attractivechaos/klib
GLibGTK 的基础库,提供 GList, GHashTable, GArray 等https://docs.gtk.org/glib/
stb纯头文件库集合,含 stb_ds(动态数组+哈希表)https://github.com/nothings/stb
libcorkC 语言工具集,含 darray, hash-map 等
ConcurrencyKit高并发无锁数据结构https://github.com/concurrencykit/ck