我怎样才能实现擦除方法?
void reserve( int newCapacity ){
Object *oldArray = objects;
int numToCopy = newCapacity < theSize ? newCapacity : theSize;
newCapacity += SPARE_CAPACITY;
objects = new Object[newCapacity];
for( int k=0; k < numToCopy; k++ )
objects[k] = oldArray[k];
theSize = numToCopy;
theCapacity = newCapacity;
delete [ ] oldArray;
}
我如何实现擦除方法,可能使用reserve()?
iterator erase ( iterator position ){
if (position + 1 != end())
copy(position + 1, finish, position);
--finish;
return position;
}
void reserve( int newCapacity ){
Object *oldArray = objects;
int numToCopy = newCapacity < theSize ? newCapacity : theSize;
newCapacity += SPARE_CAPACITY;
objects = new Object[newCapacity];
for( int k=0; k < numToCopy; k++ )
objects[k] = oldArray[k];
theSize = numToCopy;
theCapacity = newCapacity;
delete [ ] oldArray;
}
How can i implement the erase method, probably using reserve()?
iterator erase ( iterator position ){
if (position + 1 != end())
copy(position + 1, finish, position);
--finish;
return position;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来应该这样做:
Seems like this ought to do it: