我想做的是创建一个读取器类,它将获取第一个元素,对其求值,然后将其删除。所以这意味着项目必须添加在前面而不是后面。
这就是我需要做的。伪代码。
void Add( int messageCode ){ if(m_pList && messageCode!=0xFF)m_pList->push_front(messageCode); } // Adding a message; Added check if input is 0xFF.
代替
void Add( int messageCode ){ if(m_pList && messageCode!=0xFF)m_pList->push_back(messageCode); } // Adding a message; Added check if input is 0xFF.
最佳答案
如果您需要 FIFO,请查看 std::deque
类及其方法,例如 push_front
或 emplace_front
。
如果您需要 LIFO,请查看 std::stack
类。
关于C++ Deque/Vector 将项目推到前面而不是 push_back,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7700184/