李砍刀: 剩下的章节还更新吗
C语言面向对象实现滑动均值滤波与平均值滤波酆305: 接着上面的 for (int i = 0; i < a->count; i++) { sum += a->data[current]; current = (current + 1) % N; } return sum / a->count; } int main() { G test; // 初始化 memset(test.data, 0, N * sizeof(int)); test.write = 0; test.read = 0; test.count = 0; test.push = push; test.pop = pop; test.getAvg = getAvg; // 采集5个数据 int data1 = 1, data2 = 2, data3 = 3, data4 = 4, data5 = 5; test.push(&test, data1); test.push(&test, data2); test.push(&test, data3); test.push(&test, data4); test.push(&test, data5); printf("g: %f\n", test.getAvg(&test)); // 模拟每次采集到新数据,然后剔除旧数据,输出平均值 int data = 99; for (int i = 0; i < 5; i++) { test.push(&test, data); printf("g: %f\n", test.getAvg(&test)); } return 0; } 可以试试对不对
C语言面向对象实现滑动均值滤波与平均值滤波酆305: 修改的代码 #include #include #include #define N 5 typedef struct g { int data[N]; int read; int write; int count; // 当前队列中的元素数量 void (*push)(struct g*, int); void (*pop)(struct g*); float (*getAvg)(struct g*); } G; void push(G* a, int d) { a->data[a->write] = d; a->write = (a->write + 1) % N; if (a->count < N) { a->count++; } else { a->read = (a->read + 1) % N; } } void pop(G* a) { if (a->count > 0) { a->read = (a->read + 1) % N; a->count--; } } float getAvg(G* a) { if (a->count == 0) return 0.0f; float sum = 0; int current = a->read;
适航规章、标准,书籍资料下载汇总(增加DO-160G中英文版)不懂?就问……: 适航规章
C语言回调函数详解(全网最全)m0_75186829: 封神了,博主这个写得太好了