Sorting algorithm
-
I have 20 names and there makes stored in a map. My requirement is to get hghest marks of top 10 studens. please let me know the sorting algorithim to find that out. Thanks in Advance
-
I have 20 names and there makes stored in a map. My requirement is to get hghest marks of top 10 studens. please let me know the sorting algorithim to find that out. Thanks in Advance
u can use STL <algorithm> http://msdn.microsoft.com/en-us/library/ecdecxh1(VS.80).aspx[^]
-
I have 20 names and there makes stored in a map. My requirement is to get hghest marks of top 10 studens. please let me know the sorting algorithim to find that out. Thanks in Advance
You may try to implement yourself a simple sorting algorithm, like, for instance [^], it maybe an interesting experience. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
I have 20 names and there makes stored in a map. My requirement is to get hghest marks of top 10 studens. please let me know the sorting algorithim to find that out. Thanks in Advance
If you used this:
std::map<MarkType, NameType> marksAndStudents;
(where
MarkType
is the type you use for a students marks andNameType
is the type you use for a students name, then*rbegin()
points at the student with the highest mark - try this:std::map<int, std::string> s;
s.insert(std::make_pair(10, "10"));
s.insert(std::make_pair(20, "20"));
s.insert(std::make_pair(30, "30"));
s.insert(std::make_pair(40, "40"));
s.insert(std::make_pair(50, "50"));
s.insert(std::make_pair(60, "60"));
s.insert(std::make_pair(70, "70"));
s.insert(std::make_pair(80, "80"));
s.insert(std::make_pair(90, "90"));
s.insert(std::make_pair(100, "100"));
s.insert(std::make_pair(110, "110"));
s.insert(std::make_pair(120, "120"));std::map<int, std::string>::const_reverse_iterator it = s.rbegin();
for (int i=0;i<10;++i)
{
std::cout << it->second << std::endl;++it;
}Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p