Click here to Skip to main content
15,501,490 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Efficiently sort the following? Pin
arnold_w24-Aug-17 11:48
Memberarnold_w24-Aug-17 11:48 
AnswerRe: Efficiently sort the following? Pin
Richard MacCutchan24-Aug-17 22:05
mveRichard MacCutchan24-Aug-17 22:05 
AnswerRe: Efficiently sort the following? Pin
Richard Deeming25-Aug-17 2:47
mveRichard Deeming25-Aug-17 2:47 
GeneralRe: Efficiently sort the following? Pin
arnold_w28-Aug-17 1:40
Memberarnold_w28-Aug-17 1:40 
GeneralRe: Efficiently sort the following? Pin
Richard Deeming29-Aug-17 2:53
mveRichard Deeming29-Aug-17 2:53 
GeneralRe: Efficiently sort the following? Pin
arnold_w30-Aug-17 5:04
Memberarnold_w30-Aug-17 5:04 
GeneralRe: Efficiently sort the following? Pin
Richard Deeming30-Aug-17 5:40
mveRichard Deeming30-Aug-17 5:40 
AnswerRe: Efficiently sort the following? Pin
Alan N30-Aug-17 6:48
MemberAlan N30-Aug-17 6:48 
Let's do this the old way!

Sorting on multiple keys with a comparer method is straightforward (and easy to understand?). It is just a nested set of comparisons, compare the first key, if equal compare the second key, etc.

For example let's say we have a list of strings and we want a custom sort.
1) by string length
2) alphabetically within each group of equal length

The comparer method is
C#
private static Int32 SortByLengthThenAlpha(String x, String y) {
  // 1st sort
  Int32 result = x.Length.CompareTo(y.Length);
  // result will be < 0, 0, > 0

  if (result == 0) {
    // 2nd Sort, standard string sort
    result = x.CompareTo(y);

    // and so on if more is needed
    // if (result==0) {
    // }
    //
  }
  return result;
}

With an array of strings we can perform the sort with
C#
Array.Sort(strings, SortByLengthThenAlpha);

Original Order
==============
Reddish
Yellowish
Redder
Greenish
Red
Orange
Yellow
Orangy
Green

Sorted
======
Red
Green
Orange
Orangy
Redder
Yellow
Reddish
Greenish
Yellowish

Hope that helps explain the general idea. In your case the keys are the numeric values of T, H and L.

Alan.
GeneralRe: Efficiently sort the following? Pin
arnold_w1-Sep-17 0:50
Memberarnold_w1-Sep-17 0:50 
GeneralRe: Efficiently sort the following? Pin
Alan N3-Sep-17 2:13
MemberAlan N3-Sep-17 2:13 
GeneralRe: Efficiently sort the following? Pin
arnold_w3-Sep-17 3:37
Memberarnold_w3-Sep-17 3:37 
QuestionHow to use tensorflow in c# Pin
delphix518-Jul-17 1:48
Memberdelphix518-Jul-17 1:48 
AnswerRe: How to use tensorflow in c# Pin
Richard MacCutchan18-Jul-17 3:09
mveRichard MacCutchan18-Jul-17 3:09 
QuestionC++ algorithm Question Pin
Member 1310646721-Jun-17 19:29
MemberMember 1310646721-Jun-17 19:29 
AnswerRe: C++ algorithm Question Pin
OriginalGriff21-Jun-17 19:37
mveOriginalGriff21-Jun-17 19:37 
QuestionInvoice / Payments history table or statement of account Pin
Bastien Vandamme14-Jun-17 16:50
MemberBastien Vandamme14-Jun-17 16:50 
AnswerRe: Invoice / Payments history table or statement of account Pin
Gerry Schmitz14-Jun-17 17:17
mveGerry Schmitz14-Jun-17 17:17 
GeneralRe: Invoice / Payments history table or statement of account Pin
Bastien Vandamme14-Jun-17 17:46
MemberBastien Vandamme14-Jun-17 17:46 
GeneralRe: Invoice / Payments history table or statement of account Pin
Gerry Schmitz14-Jun-17 18:39
mveGerry Schmitz14-Jun-17 18:39 
AnswerRe: Invoice / Payments history table or statement of account Pin
jschell10-Jul-17 5:30
Memberjschell10-Jul-17 5:30 
QuestionChaotic image encryption algorithm by Xingyuan Wang Pin
Member 1325934114-Jun-17 5:53
MemberMember 1325934114-Jun-17 5:53 
QuestionSelecting values from list to make up totals in second list Pin
Wayne Gaylard15-May-17 22:45
professionalWayne Gaylard15-May-17 22:45 
AnswerRe: Selecting values from list to make up totals in second list Pin
Richard MacCutchan15-May-17 23:27
mveRichard MacCutchan15-May-17 23:27 
GeneralRe: Selecting values from list to make up totals in second list Pin
Wayne Gaylard15-May-17 23:34
professionalWayne Gaylard15-May-17 23:34 
AnswerRe: Selecting values from list to make up totals in second list Pin
F-ES Sitecore22-May-17 5:48
professionalF-ES Sitecore22-May-17 5:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.