473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Re: Ranking algorithm

In article <48***********************@reader4.news.tin.it>,
Giuliano Bertoletti <gb******@libero.itwrote:
>
Good. It seems to be working.

I just have to be carefull when defining the < operator since it has to
correctly handle different items with the same score.
Correctly: operator< should return false for two items that have the
same score.

So if a.score == b.score:

a < b = false
a b = false
a <= b = true
a >= b = true

One of < or is perfectly sufficient for sorting anything efficiently.
>For example:

======================= cut =======================

class CItem {
public:
char name[20];
int score;

public:
bool operator<(const CItem &I) const
{
// if i were to compare only scores, items with the same
// score would just overwrite one another.

if(score != I.score) return score < I.score;
return strcmp(name,I.name) < 0;
Pointless.
You are artificially sorting on "name" which is not in your
requirements. You may as well just keep the first one found.
You are adding one comparison to your critical loop
which if M >N is likely to have more effect than any efficiency
issue discussed aboutstd::set.

Just use the correct operator in your loop.

Want the N smallest:

if( current_item < current_stored_max )
{
// store in set
// resize set to N
// current_stored_max = get current max from set
}

Oct 20 '08 #1
0 1884

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Petre Huile | last post by:
I have designed a site for a client, but they have hired an internet marketing person to incrase their search engine ranking and traffic. He wants to put extra-large fonts on every page which will...
5
by: ED | last post by:
I currently have vba code that ranks employees based on their average job time ordered by their region, zone, and job code. I currently have vba code that will cycle through a query and ranks each...
1
by: Joseph Bloch | last post by:
In all the threads on ranking in Access queries, I've not seen anything that deals with ranking against a subset of the query results. What I need to do is take the following query results: Dept...
5
by: valglad | last post by:
Hi, The question below was posted about 4 years ago and noone was able to answer it back then. I have virtually the same type of problem so would appreciate if anyone can help. Thanks ...
6
by: sara | last post by:
I hope someone can help with this. Our director wants to have a report that will have the departments (Retail stores) across the top, stores down the side and the RANKING of the YTD dept sales...
5
by: Chris | last post by:
I was wodering if there was a way to rank numbers in a query like this #'s Rank 100 1 99 2 98 3 98 97 5 96 6 96
0
debasisdas
by: debasisdas | last post by:
Rank:-assigns A Unique Number For Each Row Starting With 1,except For Rows That Have Duplicate Values,in Which Case The Same Ranking Is Assigned And A Gap Appears In The Sequence For Each Duplicate...
2
by: smitanaik | last post by:
is there any ranking algorithm by which i can find top 10 most visited sites from the database since daatbase will have same site name repeated many times
0
by: xahlee | last post by:
I have updated the computing sites popularity ranking, based on both alexa.com and quantcast.com. The whole report nicely formatted in HTML is here: http://xahlee.org/lang_traf/lang_sites.html ...
10
by: Juha Nieminen | last post by:
Victor Bazarov wrote: If N is very large, std::set can be a real memory hog. If a more memory-efficient algorithm is needed, then a heap can be used. (The exact same type of heap as used in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.