ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i have a std::map<string,float>
which maps ip's to their load averages for the last minute
now i need those ip's who has the lowest load!
anybody knows if there is a sort algorithm i can use for a map, which sorts using the value's
don't really have the time to write a complex algorithm by myself
for now i only have a simple loop which iterates through the map
but i think it will be a little bit slow
If you need the entry with the lowest value only once, it is by far faster to iterate over the complete map (complexity: O(n)) than to sort the map and then pick the first element (complexity: O(n*log(n)).
However, if you want to sort nevertheless: Chapter 17.1 gives you the information you need.
i'm not sure, Proud, but to use a linked list i need my own sort algorithm, because the values of the linked list are pairs and the algorithm itself needs to know that they are pairs
so it's not a standard simple algorithm
(and i don't have time ;-( )
Well iirc with a double linked list if you insert items in sorted order as you build it up (O(log(n) ?) then finding the lowest load would take O(1), and you wouldnt need to have a sorting algorithm as such, as you simply assume the list is sorted when inserting or deleting. But I'm rusty after my summer after my Algorithms and Data Structures module.
Edit: searching would take O(log(n)), finding the lowest load would take O(1).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.