
c/c++
ABNQ-CN
这个作者很懒,什么都没留下…
展开
-
插入排序-一函数实现升降序的两种方式
方式一:传整数参数判断升降排序void insertion_sort(int *sort_arr, int start, int end, char sort_choice){ int i = 0, j = 0, temp = 0, k = 0; if(1 == sort_choice){//高位在前 for(j = 1; j<= end; j++){ temp = sort_arr[j]; for(i = j - 1;原创 2021-11-27 14:15:01 · 671 阅读 · 0 评论 -
C/C++ 计算某天是一年中的第几天
void TIME_CountTotalDay(time_str *time_date){ unsigned long i; //计算天数。 time_date->total_day = 0; if (time_date->month != 1) //大于1月。 { for (i = 1; i < time_date->month; i++) { if ( (i == 1) || (i.原创 2020-11-04 16:01:19 · 1355 阅读 · 0 评论 -
C/C++计算汉明距离
什么是汉明距离汉明距离是使用在数据传输差错控制编码里面的,汉明距离是一个概念,它表示的是两个数字对应二进制不同的位置的数量.汉明距离的实现顾名思义,示的是两个数字对应二进制不同的位置的数量,我们就是用最简单的方法把两个数不同的二进制位统计出来就行了(异或,相同位相同为0,否则为1) 1010b(10) ^ 0101b(5) ------------------------ 1111b(15)int Hamm原创 2020-09-24 19:20:59 · 2094 阅读 · 0 评论 -
嵌入式工程师综合笔试题之C++(含部分答案)
List item嵌入式工程师综合笔试题之C++1、 初始化和赋值的区别是什么?定义和声明的区别是什么?赋值操作是在两个已经存在的对象间进行的,而初始化是创建一个新的对象并且初始化来源于另一个存在的对象.初始化是在编译时进行的,而赋值是在函数或程序运行时进行.定义也是申明,extern声明不是定义,及不分配内存空间.声明有初始化就被当做定义.带有{}就是定义,否则就是声明.除非有extern关键字,否则就是变量的定义.2、 什么是“引用”?引用和指针的区别?声明和使用“引用”要注意哪..原创 2020-09-23 11:20:41 · 881 阅读 · 0 评论 -
Modbus的CRC16和LRC计算方式.
Modbus计算CRC16什么是CRC?循环冗余校验(CRC) 域为两个字节,包含一个二进制16 位值。附加在报文后面的CRC 的值由发送设备计算。接收设备在接收报文时重新计算CRC 的值,并将计算结果于实际接收到的CRC值相比较。如果两个值不相等,则为错误。CRC 的计算, 开始对一个16位寄存器预装全1. 然后将报文中的连续的8位子节对其进行后续的计算。只有字符中的8个数据位参与生成CRC 的运算,起始位,停止位和校验位不参与CRC 计算。CRC 的生成过程中, 每个 8–位字符与寄存器原创 2020-09-14 18:53:57 · 1369 阅读 · 0 评论 -
c/c++ if分支的消除,提高代码的运行效率
一般的if语句if( v < 10){ v + 48;}else{ v + 50;}改进之后的语句(没有分支了)v + 55 - ( ( (v- 10) >> 15) & 7 );解释1、if语句可以改进为:v + ( v < 10 ? 48 : 50).2、后面的三元运算符的原型就是 c ? x : y,此处替换成一个与此等价的表达式:y - ( c~ ? ( y - x ) : 0).3、如果 c~用-1表示为真,0表示假的话,可以替换成原创 2020-08-03 15:40:26 · 1007 阅读 · 1 评论 -
双链表-双链表的排序(非节点值排序,而是节点排序)
双链表的排序#include <stdio.h>#include <stdlib.h>// 双链表typedef struct node_t{ int val; int idx; struct node_t *next, *prev;}in, *in_p;void showList( struct node_t *h ){ printf("++++++++++++showList+++++++++++++\n"); while( h ){ pri原创 2020-06-19 17:29:34 · 187 阅读 · 0 评论 -
链表-链表的排序(非节点值的排序,而是节点排序),对什么排序又排序函数的参数决定(条件函数)
节点排序的函数int cmpScore( struct node_t *n1, struct node_t *n2 ){ return n1->score - n2->score;}int cmpVal( struct node_t *n1, struct node_t *n2 ){ return n1->val - n2->val;}void sortList( struct node_t **h, int (*fp)(struct node_t *,原创 2020-06-18 19:34:44 · 198 阅读 · 0 评论 -
链表-在链表中找到想找的值,并把想找的值摘取出来形成新的链表而原来的链表只是提出了想找的结点。以及链表的2种头插和2中尾插法
2种头插法的写法//第一种方法struct node_t* insertHead( struct node_t *h, struct node_t *n ){ n->next = h; return n;}//第二种方法void insertHead1( struct node_t **h, struct node_t *n ){ n->next = *h; *h = n;}2种尾插法的写法//第一种方法struct node_t *insertTail(原创 2020-06-18 19:15:36 · 216 阅读 · 0 评论 -
c/c++从字符串读取内容,并且对其排序之后保存到结构体数组里面(学习笔记)
从字符串读取内容,并且对其排序之后保存到结构体数组里面#include <stdio.h>#include <string.h>#include <stdlib.h>#define NUM 4struct student_t{ char *name; int age; int score;}; // 用字符串内容初始化结构体内存void initCls( struct student_t *p, char *s ){ int i = 0原创 2020-06-14 17:00:05 · 902 阅读 · 0 评论 -
c/c++查找字符串中最长的和最短的单词,最长和最短可能不止一个,并统计起格式
查找字符串中最长的和最短的单词,最长和最短可能不止一个,并统计起格式#include <stdio.h>#include <stdlib.h>#include <string.h>#define LEN 20struct Word{ char *name; int len;}tmp;void destroys(struct Word *arr, int j){ for(int i = j; i < LEN; i++){ free(ar原创 2020-06-14 15:28:24 · 2655 阅读 · 1 评论 -
c/c++ 字符串函数(字符串函数的源代码)的实现strlen、strcpy、strcmp、strncmp、strcasecmp、strtok、strstr(面试题)
c/c++实现各种字符串函数的功能(字符串源码)//========================================//*author: ABNQ//*email:abnq_cn@qq.com//*create time ://*filename:my_str.c//*description://========================================#include <stdio.h>#include <stdlib.h>原创 2020-06-14 10:59:40 · 355 阅读 · 0 评论