I know you can do this by it's key, but what if I want to treat it like a vertual database where I can sort it by it's object's properties. The door to life is never locked, but few have the knowledge to open it.
You can sort a collection, but it ain't pretty. If you've got lots of memory available, just read it out of collection A into B in the order you want. If you want to do an in-place sort, then things get really ugly. You'd have to loop through the collection re-assigning the key values so that they appear in correct order. You could do an insertion sort, but modified where when you need to swap two items, you'd copy them out to temp object variables, delete the items from the collection, swap their key values, then add them back in. When you get done, you could iterate through the collection by key value to get them in ascending order.
If you don't have a copy already, pick up:
Practical Algorithms for Programmers
Paperback, 592 Pages, Edition Number 01, Addison-Wesley Longman, Incorporated, June 1995
ISBN: 020163208X
The algorithms in the book are written in C, but they're very readable, since the author doesn't do any tricks with pointers. This book is highly reccommended.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.