Sign in to follow this  

Any good list-classes available?

This topic is 4355 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Do any1 have such a thing to recommend? I now use the std: lists which work but maybe there's something more convinient? After all, much of my hassle regards lists, iterators and stuff. Wanna make it more streamlined. And maybe with some builtin functions like sortList etc. Thankful for any tips Suliman

Share this post


Link to post
Share on other sites
Quote:
Original post by suliman
Do any1 have such a thing to recommend? I now use the std: lists which work but maybe there's something more convinient?


Not really, no. At least not in C++.

Quote:
After all, much of my hassle regards lists, iterators and stuff. Wanna make it more streamlined.


Streamlined how?

Quote:
And maybe with some builtin functions like sortList etc.


std::list does have a sort() member function.

Share this post


Link to post
Share on other sites
What is your chief complaint about the std:: data structures? They are pretty convienient and sort well using std::sort (or you could even make a custom sort, using iterators)

Share this post


Link to post
Share on other sites
No real complain. I just have heard people complain about it and thought there was something "better".

But ok, i guess its fine, then:

I tried to build a sort before but it doesnt seem to do anything. Where do i place the call and exactly how do i do it?

I have for example lists that holds pointers to my town-class <town *>. I want to do a sort() that puts towns with lower posX first:

class town{
public:
int posX;
//...
//...

};

Could any1 help me out? Thanks a lot.

Share this post


Link to post
Share on other sites
My magical google wand takes me to http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20408038.html

I don't think it is a very good idea to sort a std::list though, remember
that the list is a linear data structure, no random iterators. If you do call the sort functionality a lot, it may lower your application performance !

You can also use CList in MFC classes, it is pretty simple to use.No sort() though :(

Share this post


Link to post
Share on other sites
Quote:
Original post by Pro-XeX
I don't think it is a very good idea to sort a std::list though, remember
that the list is a linear data structure, no random iterators. If you do call the sort functionality a lot, it may lower your application performance !

Since std::list is a node-based container it can be much more efficient for sorting large objects since it only needs to swap pointers, not objects. std::list::sort also has exactly the same time complexity as the non-member sort algorithm.

Enigma

Share this post


Link to post
Share on other sites
>Since std::list is a node-based container it can be much more efficient for
>sorting large objects since it only needs to swap pointers,
... or maybe use a vector containing pointers to the objects?

Share this post


Link to post
Share on other sites

This topic is 4355 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this