Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
435 views
in Technique[技术] by (71.8m points)

双端循环队列的头部入队问题

一个空的双端循环队列(数组实现),此时它的队头应该是在index=0的位置,如果此时从队头入队,那么是插入到index=0的位置吗。还是说插入到index=5的位置?

image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

插入到5,当前队列容量capacity6, front = 0, 队首插入数据时,front更新为front = (front - 1 + capacity) % capacity = (0 - 1 + 6) % 6 = 5


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...