Hi there I am using the STL vector and I was wondering, is there an
existing method for reversing the contents of one vector?
e.g. vector<int> v1 which has entries 1,2,3,4,5
and I want to end up with v1=5,4,3,2,1 or perhaps leave v1 intact and
generate a new vector v2=5,4,3,2,1
so, does the STL have something allready? or do I have to do it manualy?
Thanks
V.Z. 6 37293
On Tue, 24 Jun 2003 03:32:41 +0100,
Vasileios Zografos <vz*******@bcs.org.uk> wrote: Hi there I am using the STL vector and I was wondering, is there an existing method for reversing the contents of one vector?
e.g. vector<int> v1 which has entries 1,2,3,4,5 and I want to end up with v1=5,4,3,2,1 or perhaps leave v1 intact and generate a new vector v2=5,4,3,2,1
so, does the STL have something allready? or do I have to do it manualy?
std::reverse(v1.begin(), v1.end());
or:
std::vector<whatever> v2(v1.size());
std::reverse_copy(v1.begin(), v1.end(), v2.begin());
Surely you have a book with this stuff in it?
Or even: http://www.sgi.com/tech/stl/
--
Sam Holden
> Surely you have a book with this stuff in it?
Nope. But can you suggest one?
Thank you for the help.
V.Z.
"Vasileios Zografos" <vz*******@bcs.org.uk> wrote in message
news:bd**********@news8.svr.pol.co.uk... Surely you have a book with this stuff in it?
Nope. But can you suggest one?
Thank you for the help. V.Z.
The Standard C++ library by Josuttis. sh*****@flexal.cs.usyd.edu.au (Sam Holden) wrote in message news:<slrnbffeee.cah.sh*****@flexal.cs.usyd.edu.au >... On Tue, 24 Jun 2003 03:32:41 +0100, Vasileios Zografos <vz*******@bcs.org.uk> wrote: Hi there I am using the STL vector and I was wondering, is there an existing method for reversing the contents of one vector?
e.g. vector<int> v1 which has entries 1,2,3,4,5 and I want to end up with v1=5,4,3,2,1 or perhaps leave v1 intact and generate a new vector v2=5,4,3,2,1
so, does the STL have something allready? or do I have to do it manualy?
std::reverse(v1.begin(), v1.end());
or:
std::vector<whatever> v2(v1.size()); std::reverse_copy(v1.begin(), v1.end(), v2.begin());
The latter can also be written as
std::vector< > v2( v1.rbegin(), v1.rend() );
which saves v1.size() default-initializations of whatevers (which might
be impossible, default ctors aren't mandatory)
Regards,
--
Michiel Salters
> > std::vector<whatever> v2(v1.size()); std::reverse_copy(v1.begin(), v1.end(), v2.begin());
The latter can also be written as
std::vector< > v2( v1.rbegin(), v1.rend() );
which saves v1.size() default-initializations of whatevers (which might be impossible, default ctors aren't mandatory)
Regards, -- Michiel Salters
Default ctors are mandatory to be compliant with the STL.
john
"John Harrison" <jo*************@hotmail.com> wrote in message news:bd************@ID-196037.news.dfncis.de... which saves v1.size() default-initializations of whatevers (which might be impossible, default ctors aren't mandatory)
Regards, -- Michiel Salters
Default ctors are mandatory to be compliant with the STL.
Default constructors are NOT mandatory. The requirement is that the contents
be copy constructable and assignable. The few functions that need to be able
to create "defaulted" objects take a parameter (defaulted to a default constructed
object) that is copied to these objects. If you provide a non-default constructed
object for these functions, your object does not need default constructor. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Raymond Hettinger |
last post by:
Here is a discussion draft of a potential PEP.
The ideas grew out of the discussion on pep-284.
Comments are invited. Dart throwing is optional.
Raymond Hettinger
...
|
by: Raymond Hettinger |
last post by:
Please comment on the new PEP for reverse iteration methods.
Basically, the idea looks like this:
for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0
<do something with i>
The...
|
by: Raymond Hettinger |
last post by:
Based on the feedback here on comp.lang.python, the pep has been
updated:
www.python.org/peps/pep-0322.html
The key changes are:
* reversed() is being preferred to ireverse() as the best...
|
by: Alex Vinokur |
last post by:
I am looking for any custom allocator sample code for std::vector.
Thanks.
--
Alex Vinokur
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn
|
by: Aamir Mahmood |
last post by:
What could be the fastest method to reverse a string.
Speed really matters for my application. Average size of string that comes
to my function is around 200K - 300K.
Currently i am using the...
|
by: Jonathan Wood |
last post by:
Is it just me? It seems like one moving from MFC to C# loses some string
functionality such as the two mentioned in the subject.
Did I miss something?
--
Jonathan Wood
SoftCircuits...
|
by: analoveu |
last post by:
I have a problem with using the reverse method
any one give me an exmample or correct my error inside this code
String p="";
for(int x=0 ; x<=3 ; x++)
p+=x;
System.out.print(p);
String...
|
by: analoveu |
last post by:
I want to know if there is a built-in method in the java class library and ready for use .If there how can i use it to reverse a string and print it
I saw i the JDK6.0 Docs this method
java.lang...
|
by: T. Crane |
last post by:
Hi,
I'm struggling with how to initialize a vector<vector<double>>
object. I'm pulling data out of a file and storing it in the
vector<vector<double>object. Because any given file will have a...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
| |