STL、列表、迭代器
请购买我的英语)))
我有这个问题: 我必须使用可能的编辑项目迭代 STL 列表中的项目:删除、添加、编辑。 这是我的方法:
void MoveOnNewPlace(Tree& parent, Tree& child)
{
Tree *temp=&parent;
while(temp->GetParent()!=temp && temp->GetItem().GetChar()=='(')
temp=temp->GetParent();
if(*temp==parent) return;
Tree newTr(child);
newTr.SetParent(*temp);
temp->GetSubNodes()->push_back(newTr); //(Tree(child,temp));
parent.GetSubNodes()->remove(child);
}
list<Tree>::_Nodeptr ptr=nodes->_Myhead->_Next;
unsigned int i=0;
while(i++<nodes->size() && ptr!=0)
{
Prepair(ptr->_Myval);
if(ptr->_Myval.GetItem().GetChar()=='[')
MoveOnNewPlace(t,ptr->_Myval);
ptr=ptr->_Next;
}
有人可以告诉我如何以其他方式做到这一点,而无需明确使用 _Myhead、_Myhead 等。 谢谢!
Exscusme buy my English )))
I have this problem:
I must iterate items in STL list with posible editing items: remove, add, edit.
This is my approach:
void MoveOnNewPlace(Tree& parent, Tree& child)
{
Tree *temp=&parent;
while(temp->GetParent()!=temp && temp->GetItem().GetChar()=='(')
temp=temp->GetParent();
if(*temp==parent) return;
Tree newTr(child);
newTr.SetParent(*temp);
temp->GetSubNodes()->push_back(newTr); //(Tree(child,temp));
parent.GetSubNodes()->remove(child);
}
list<Tree>::_Nodeptr ptr=nodes->_Myhead->_Next;
unsigned int i=0;
while(i++<nodes->size() && ptr!=0)
{
Prepair(ptr->_Myval);
if(ptr->_Myval.GetItem().GetChar()=='[')
MoveOnNewPlace(t,ptr->_Myval);
ptr=ptr->_Next;
}
Could someone tell me how I can do it in other way without explicity using _Myhead, _Myhead and so on.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否考虑过使用
list::iterator
和list::const_iterator
?Have you considered using
list<Tree>::iterator
andlist<Tree>::const_iterator
?