Skip to content

implement basic and important algorithm and data structure with C++ and UniTest(gtest)

Notifications You must be signed in to change notification settings

lianzeng/Algorithm

Repository files navigation

Algorithm and Data Structure implementation using C++ with gtest framework.

All of the algorithm is written in C++11 online cyber dojo . All the code is written by zeng,liang.

Note: if you open the URL, please Don't modify the source code.

Currently, I have complete the following programme:

1.Heap(minHeap,maxHeap) 最小堆,最大堆

2.remove duplicated elements from unsorted forward list从无序单链表移除重复元素

3.reverse forward list 反转单链表

4.hano tower 汉诺塔

5.common code pucch design(class design) C++模板+继承

6.median of two sorted array 两个有序数组的中值

7.bowling game 保龄球游戏

8.merge sort(recursive and non-recursive) 归并排序,递归 + 非递归

9.quick sort (recursive and non-recursive) 快速排序,递归 + 非递归

10.binary search for sorted vector 二分查找

11.Count Coins 硬币组合,递归+非递归

12.Balanced Parentheses 括号配对

13.24点游戏 关键是数据结构的设计,用来回溯计算过程

14.anagrams变位词, 全排列

15.Eight Queens 八皇后

16.fibonacci 斐波那契

17.Find Path Avoid Obstacles 躲避障碍寻路

18.Factorize prime factors 质因数分解

19.magic square(数独游戏) 给定一个数列,组成3*3方正,任何一行/列/对角的和都相等,递归实现,每次递归选一行数,剪枝策略:行和=sum/3;代码非常的清晰易懂(宏函数技巧使用),一气呵成,使用了bitset来辅助选择数字;

20.数独游戏golang版本,打印所有结果 , 代码简洁清晰, 结果按升序输出,行列颠倒也认为是不同的结果

21.array shuffle

22.combine to largest number

23.find adjacent 1bits number(Diversion) 非常难得的一题,打印详细状态转换,迭代递推思路清晰,N bit的数是由N-1 bit的数在尾部扩展1bit(=0 ,1), 假定(N-1) bit 的数分成2组S+V,S组满足条件(has adjacent 1),V组不满足条件(又细分为偶数组和奇数组:Vodd+Veven),奇数组是潜在转化组,只要尾部加bitvalue=1就转移到S组,由此得出结论:N bit的S组=(Sn-1) + Vodd_n-1 ; Vodd_n = Vn-1 - 转正(Vodd_n-1); Veven_n = 不满足条件 = Vn-1; 得到2个递推公式为: Sn=2*Sn-1 + VOddn-1; Voddn=Vn-1 - Voddn-1 = power(2, n-1)-Sn-1 - Voddn-1,进一步抽象得到2个公式:Yn=f1(Yn-1, Xn-1); Xn = f2(Yn-1, Xn-1); 这是一个二元状态转移方程,也是2维动态规划问题。

24.spell number in english

26.remove duplicate from unsorted list

27.buy book with best discount, DP. use Cache and Quick-Cut to improve performance(if not cache, will run long long time..) codeJam, 动态规划,使用缓存和减枝 来加速

28.BigNumberPlus(大数相加) codeJam

29.SearchPath Any Start&&End, with required steps 路径搜索

30.Candy Dispatch codeJam

31.DFS-BFS(非递归遍历) 深度,广度 遍历,非递归

32.Red-Black-BST(print) 打印红黑树

33.BTree(print) 打印B树

34.queue(implement with cycle-array) 实现有界队列

35.List(BiLinkList,iterator) 实现迭代器

36.rar payload build(3GPP)

37.reverse integer 数值反转

38.string to integer(atoi) 字符串转数值

39.remove Nth node from End of list 从链表移除倒数第N个节点

40.merge two sorted lists 归并2个有序链表,代码简洁优雅

41.merge N sorted link list by golang 归并N个有序链表,借助golang 的heap数据结构,实现流式输出排序后的结果,这段代码用在了生产环境中

42.decorator c11 装饰者模式

43.cJSON test case 写的几个测试用例基本覆盖了cJSON库的用法,由于cJSON.h原始文件太大,会被cyberDojo截断,所以没法跑,但是在本地可以跑过, cJSON Github: https://github.com/DaveGamble/cJSON

44.有序链表通过改造可以提升查找性能:a)采样出2层链表(类似跳表); b)每个node变为一个小数组(类似ziplist); c)非线形化,变为二叉搜索树;

About

implement basic and important algorithm and data structure with C++ and UniTest(gtest)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published