Java For Loop in a table

综合编程 2018-05-16

This question is probably best suited towards anyone with some insight into disk read scheduling.

I have the code:

for(int i = readqueue_tail; i<readqueue_head; i++)

I then use i to access elements in a readqueue array, which goes up to 255. However, once the queue is filled, it starts filling again from 0 (as these requests will have been serviced it doesn't matter).

The issue I'm having is searching from the tail up to the readqueue_head as when the head loops round and goes past 0 again the loop condition fails. How would I go about fixing this?

Other options is just use modulo.

int i = readqueue_tail;
while (i != readqueue_head)
{
    i = (i + 1) % 256;
}
Hello, buddy!

责编内容by:Hello, buddy! (源链)。感谢您的支持!

您可能感兴趣的

淘汰?不存在的!Java程序员如何避免职业危机... Java行业在当下人才是供不应求,但是作为的你也得居安思危,你要知道你身处的是一个高速变化的行业,稍不留意你的位置还是存在被取代的风险,那么对于一个Java程序员来说,要如何避免被淘汰呢? 1.时...
Java面试HTTP篇之一:HTTP协议 一、技术基石及概述 问:什么是HTTP? 答:HTTP是一个客户端和服务器端请求和响应的标准TCP。其实建立在TCP之上的。 当我们打开百度网页时,是这样的: https:/...
Ghacks Deals: The Complete Computer Science Bundle... The Complete Computer Science Bundle includes eight programming related courses for languages s...
java设计模式-单例模式 转载请注明原文地址:http://www.cnblogs.com/geekda/p/9033815.html 单例模式是23种设计模式中比较常见的一种创建式模式,使用单例模式的目的就是为了...
Pattern Matching In Java java8虽然加入了一些函数式的特性,但是紧紧只是迈出了一小步,Classic FP 即:ADT(algebraic data type) + interpreter 的方式并不被直接支持,...