数据结构自打刚开始上学到工作都是吹牛、侃大山必备神器。所以一直都要保持总结和提高。
0x00 数据结构三大马车
数据模型定义,数据模型操作, 数据显示
数据模型定义:由单一弱数据类型,变成了由多个弱数据类型组成的强类型
typedef struct tag_data{
char name[20];
int Mathematics;
int Chinese;
}student;
数据模型操作:对数据进行业务操作
/******
@@describe: 求两门成绩的平均成绩
@@parameter: student* pstStudent
@@return: -1:功能调用失败
*/
int CalculationAvgScore(student* pstStudent)
{
if (NULL == pstStudent)
{
printf("pstStudent is null! \n");
return -1;
}
int outScore = (pstStudent->Chinese + pstStudent->Mathematics) / 2;
return outScore;
}
0x01 实例代码
//业务实现:分数总和、平均分
//数据结构定义
typedef struct tag_data{
char name[20];
int Mathematics;
int Chinese;
}student;
/******
@@describe: 计算平均分成绩
@@parameter: student* pstStudent
@@return: -1:功能调用失败
*/
int CalculationAvgScore(student* pstStudent)
{
if(NULL == pstStudent)
{
printf("pstStudent is null! \n");
return -1;
}
int outScore = (pstStudent->Chinese + pstStudent->Mathematics)/2;
return outScore;
}
/******
@@describe: 计算总分成绩
@@parameter: student* pstStudent
@@return: -1:功能调用失败
*/
int CalculationTotalScore(student* pstStudent)
{
if(NULL == pstStudent)
{
printf("pstStudent is null! \n");
return -1;
}
int outScore = (pstStudent->Chinese + pstStudent->Mathematics);
return outScore;
}
int main()
{
struct student guazi{1,"guazi", 85,94};
//显示数据处理后的结果
printf("avg score:%d \n", CalculationAvgScore(&guazi));
printf("total score:%d \n", CalculationTotalScore(&guazi));
return 0;
}
0x002 经验
瓜子以前写代码也是:老夫就是一把梭,复制,黏贴,就是干。效率虽然高,但也是经验浅薄,没少返工,离职也对
以前工作进行了总结,如何有经验的进行代码功能的开发:
1.先分析清楚业务需求。
2.功能函数伪代码编写
3.编写功能代码
4.进行功能代码测试
5.编写测试文档
6.上传功能代码到服务器
7.提交功能任务进度