Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

队列中的queue_back函数有错误? #5

Closed
ningyuwhut opened this issue Sep 13, 2013 · 2 comments
Closed

队列中的queue_back函数有错误? #5

ningyuwhut opened this issue Sep 13, 2013 · 2 comments

Comments

@ningyuwhut
Copy link

/**

  • @brief 获取队首元素.
  • @param[in] q 队列对象的指针
  • @return 队首元素
    */
    queue_elem_t queue_back(const queue_t *q) {
    return q->elems[q->rear - 1];
    }

最后一个元素的下标应该是 ( q-rear-1+q-capacity ) % q-capacity?

@soulmachine
Copy link
Owner

这里没有任何问题。

修改操作,如queue_push(), queue_pop(),需要考虑取模的问题
只读操作,如queue_front(), queue_back(),不需要,直接访问就是了

@ningyuwhut
Copy link
Author

rear不会出现为0的情形吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants