如何在没有条件的情况下向后迭代循环缓冲区? [英] How do you iterate backward over circular buffer without a conditional?

查看:117
本文介绍了如何在没有条件的情况下向后迭代循环缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用余数运算符很容易通过循环缓冲区向前迭代而不使用条件...

Iterating forward through a circular buffer without using a conditional is easy with the remainder operator...

iterator =(iterator + 1) %buffer_size;

我不能为我的生活找出反向操作,向后迭代。

I can't for the life of me figure out the reverse operation, iterating backward.

推荐答案

iterator =(iterator + buffer_size - 1)%buffer_size 为你工作吗?少走一步。

Does iterator = (iterator + buffer_size - 1) % buffer_size work for you? Go one less than all the way around.

这篇关于如何在没有条件的情况下向后迭代循环缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆