C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

std::list Position eines Elements ändern

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German)
View previous topic :: View next topic  
Author Message
Andreas Volz
Guest





PostPosted: Thu Nov 02, 2006 3:25 am    Post subject: std::list Position eines Elements ändern Reply with quote



Hi,

ich habe eine std::list mit Zeigern als Elemente. Jetzt möchte ich ein
bestimmtes Element an die erste Stelle der Liste verschieben. Wie macht
man das am besten?

Momentan suche ich das zu verschiebende Objekt in der Liste, entferne
es mit erase() und füge es erneut am Anfang der Liste ein. Ich bin mir
nicht sicher ob das so gut funktioniert, wenn man keine Zeiger, sondern
Objekte in der Liste hat. Irgendwelche Anmerkungen zu meiner Lösung?

Gruß
Andreas
Back to top
Hubert Schmid
Guest





PostPosted: Thu Nov 02, 2006 4:54 am    Post subject: Re: std::list Position eines Elements ändern Reply with quote



Andreas Volz <usenet-spam-trap (AT) brachttal (DOT) net> writes:

Quote:
ich habe eine std::list mit Zeigern als Elemente. Jetzt möchte ich
ein bestimmtes Element an die erste Stelle der Liste verschieben.
Wie macht man das am besten?

Dafür gibt es die Member-Funktion splice:

std::list<int> values;
std::list<int>::iterator p = ...;
values.splice(values.begin(), values, p);

--
Hubert Schmid - http://www.z42.de
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.