添加基本的代码规范

This commit is contained in:
nonstriater
2015-11-30 10:53:05 +08:00
parent 8f78235a28
commit b2aaaafefa
3 changed files with 156 additions and 48 deletions
+57
View File
@@ -191,6 +191,63 @@ http://openjudge.cn/ POJ。这有个POJ上的ACM训练方案 http://www.java3z
http://ac.jobdu.com/index.php 九度OJ
## C语言代码规范
这里面的代码均使用C语言完成,代码规范主要有:
### 符号命名
**变量名**
**局部变量** 尽量短,能表达清楚意思即可,能简写就简写,比如"err" 表示 "error"; "fd" 表示文件描述符 ,循环变量可以使用i,j,k ;结构体成员变量不需要"m_"前缀;全局变量"g_"开头
**常量名/宏定义** 全大写,单词之间"_"分割,如 "MAX_NUMBER_OF_SLAB_CLASSES" ;
对于options 宏定义,适当使用前缀 ,比如:
```
/* Client classes for client limits, currently used only for
* the max-client-output-buffer limit implementation. */
#define CLIENT_TYPE_NORMAL 0 /* Normal req-reply clients + MONITORs */
#define CLIENT_TYPE_SLAVE 1 /* Slaves. */
#define CLIENT_TYPE_PUBSUB 2 /* Clients subscribed to PubSub channels. */
#define CLIENT_TYPE_MASTER 3 /* Master. */
#define CLIENT_TYPE_OBUF_COUNT 3
```
枚举使用前缀:
```
enum conn_states {
conn_listening, /**< the socket which listens for connections */
conn_new_cmd, /**< Prepare connection for next command */
conn_waiting, /**< waiting for a readable socket */
conn_read, /**< reading in a command line */
conn_parse_cmd, /**< try to parse a command from the input buffer */
conn_write, /**< writing out a simple response */
conn_nread, /**< reading in a fixed number of bytes */
conn_swallow, /**< swallowing unnecessary bytes w/o storing */
conn_closing, /**< closing this connection */
conn_mwrite, /**< writing out many items sequentially */
conn_closed, /**< connection is closed */
conn_max_state /**< Max state value (used for assertion) */
};
```
**函数命名 ** 全小写,单词之间"_"分割。如"split_cmdline_strerror()"
### 注释
所有注释使用 "/* 这里是注释 */ "
### 其他
合理使用static,const 等关键字,能提升程序的安全性,也能避免函数命名冲突
合理使用数据类型:rel_time_t,uint8_t,uint32_t,uint64_t,size_t
养成良好的代码规范习惯,不但可以写出优质的代码,也可以更快的阅读其他优秀开源代码。
## 联系
[@移动开发小冉](http://weibo.com/ranwj)
+30
View File
@@ -0,0 +1,30 @@
### 查找算法
#### 顺序查找
顺序表查找
#### 二分查找
有序表中查找我们会使用二分查找。
```
void binary_search()
```
#### 分块查找
块内无序,块之间有序;可以先二分查找定位到块,然后再到块中顺序查找
#### 动态查找
>这里之所以叫 动态查找表,是因为表结构是查找的过程中动态生成的
二叉排序树,AVL树,B- ,B+
#### 哈希表
O(1)
+69 -48
View File
@@ -6,67 +6,108 @@
3. 结构之法: 对字符串,链表,队列,树的操作
4. 数学之趣: 一些数学问题
《剑指offer》中已经出现的题目先不写了
### 游戏之乐
####
####
####
####
####
####
### 数字之魅
####
#### 二进制数中1的个数
#### 阶乘
####
#### 寻找发帖"水王"
####
#### 1的数目
####
#### 寻找最大的k个数
####
#### 精确表达浮点数
####
#### 最大公约数
#### 找符合条件的整数
#### Fibonacci数列
#### 寻找数组中的最大值和最小指
#### 寻找最近点对
#### 快速寻找满足条件的两个数
#### 子数组的最大乘积
#### 求数组的子数组之和的最大值
#### 子数组之和的最大值
#### 数组中最长递归子序列
#### 数组循环移位
#### 数组分割
#### 区间重合判断
### 结构之法
####
#### 字符串移位包含的问题
####
#### 电话号码应对英语单词
####
#### 计算字符串的相似度
####
#### 从无头单链表中删除节点
####
####
#### 最短摘要生成
#### 判断2个链表是否相交
#### 队列中取最大值
#### 求二叉树中节点的最大距离
#### 重建二叉树
#### 程序改错
### 数学之趣
@@ -75,26 +116,6 @@
####
####
####
####
####
####