Sorting problem, c# or in general

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi everybody.
Can somebody direct me to a correct algorithm to solve the sort problem of
the following array of data:

ServerWeb.*
ServerWebSomething1
ServerWebSomething2
ServerWeb3
ApplicationServer1
App.*
ApplicationServer2

should be sorted as this:
ApplicationServer1
ApplicationServer2
App.*
ServerWebSomething1
ServerWebSomething2
ServerWeb3
ServerWeb.*

The point is that the data is first sorted alphabetically, and then withing
the similar types of data I need to get the data with more specific to the
top and those less specific to the bottom.
For instance, as ServerWeb.* covers all servers that starts with the
"ServerWeb" it is the least distinctive, while ServerWebSomething1 is the
most distinctive in that subgroup.

This just puzzles me, I would appreciate any algorithm in any language if C#
example is not available.

Thanks.
 
Mirano said:
Hi everybody.
Can somebody direct me to a correct algorithm to solve the sort problem of
the following array of data:

ServerWeb.*
ServerWebSomething1
ServerWebSomething2
ServerWeb3
ApplicationServer1
App.*
ApplicationServer2

should be sorted as this:
ApplicationServer1
ApplicationServer2
App.*
ServerWebSomething1
ServerWebSomething2
ServerWeb3
ServerWeb.*

The point is that the data is first sorted alphabetically, and then withing
the similar types of data I need to get the data with more specific to the
top and those less specific to the bottom.
For instance, as ServerWeb.* covers all servers that starts with the
"ServerWeb" it is the least distinctive, while ServerWebSomething1 is the
most distinctive in that subgroup.

This just puzzles me, I would appreciate any algorithm in any language if C#
example is not available.

You just need to implement IComparer and sort strings in your
particular way - which looks like it's basically still an ordinal sort,
but treat any letters as coming before any non-letters.
 
Okay, I will try to code it that way. Thanks.

Jon Skeet said:
You just need to implement IComparer and sort strings in your
particular way - which looks like it's basically still an ordinal sort,
but treat any letters as coming before any non-letters.
 
Back
Top