English 中文(简体)
1. 区分排满和空洞
原标题:Differentiating between queue full and queue empty
  • 时间:2010-12-27 17:16:26
  •  标签:
  • c

I am using a an array with a write index and a read index to implement a straightforward FIFO Queue. I do the usual MOD ArraySize when incrementing the write and read index. Is there a way to differentiate between queue full and queue empty condition (wrIndex == rdIndex) without using any additional queuecount and also without wasting any array entry i.e . Queue is full if (WrIndex + 1 ) MOD ArraySize == ReadIndex

最佳回答

我接着举了一个阵列,以发现问题的全部状况,特别是如果你重新处理不同的read子/tas,即生产者和消费者。 另一条旗帜不断跟踪这一局势,增加了必要的锁锁,以保持事态的一致,并增加了引入种族条件的某种丑恶的可能性。 如果你能够使用一个关键部分(如你在评论中所提到的)来确保事情是一回事,情况就更是如此。

你们至少需要一部分时间来跟踪这一状况,这很可能意味着至少是轻而易举的。 假设你在座标上有<代码>ints,你只保留了3个区域援助团,你将再另外 several一些方案形象(这或许不是宝贵的,因此可能无关紧要)。 如果你在用于储存其他国旗的沥青中保留国旗,那么,你还必须以隐蔽的安全方式,进一步确定/测试/清除该国旗,以确保其他轨道不会腐败。

如果你重新找你的话,那么你可能不会节省任何东西,那么你就可以认为,哨兵是你必须带别处的旗帜。 但现在你们必须拥有no。 处理国旗的法典外。

如果你真的需要这个额外项目,并铭记如果你重新提出问题,那么额外问题可能就没有真正的额外空间。

问题回答

不是阅读和书写指数,你可以使用读索引和格票。 从点上看,如果问题完全空出,你可以轻易听说。 书面指数可计算为(阅读指数+格计算) mo阵阵数。

问题究竟是什么错误? 我认为,我仍然使用一个可点数变量。 否则,另一个可能的解决办法是使用一份相关清单。 记忆使用量低,删除第一点内容,是容易的,这只是确保你有点人到名单的头部和尾部。

基本上,你只需要一个单独的附加轨道,以表明目前问题空洞。 也许,你会把某些地方 away开,例如,在你的一个指数中,最显著的界限(在你只需要把实际指数纳入你的阵列的地方,创造性地打下下下下轨道)。

但坦率地说,我只问一问,如果我确实需要这一空间,而不要bit。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签