POV-Ray : Newsgroups : povray.off-topic : C++ questions : Re: C++ questions Server Time
7 Sep 2024 09:21:50 EDT (-0400)
  Re: C++ questions  
From: Warp
Date: 28 Sep 2008 09:23:25
Message: <48df854c@news.povray.org>
Orchid XP v8 <voi### [at] devnull> wrote:
> >   Note that erase() is an O(n) operation.

> Yeah, that's kind of unavoidable.

  If the vector doesn't need to preserve the order of the elements then
you can remove the element in O(1) like this:

theVector[smallestInd] = theVector.back();
theVector.pop_back();

  In other words, copy the last element over the element to be removed,
and then remove the last element.

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.