473,385 Members | 1,753 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,385 software developers and data experts.

Sorting problem, c# or in general

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.
Jul 22 '05 #1
2 1252
Mirano <Mi****@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 22 '05 #2
Okay, I will try to code it that way. Thanks.

"Jon Skeet [C# MVP]" wrote:
Mirano <Mi****@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 22 '05 #3

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

Similar topics

18
by: Matthias Kaeppler | last post by:
Hi, in my program, I have to sort containers of objects which can be 2000 items big in some cases. Since STL containers are based around copying and since I need to sort these containers quite...
17
by: Matt Kruse | last post by:
I'm looking for the best JS/CSS solution to add functionality to tables. The only browser which needs to be supported is IE5.5+, but no activeX can be used. to be able to do: - Fixed header row...
22
by: mike | last post by:
If I had a date in the format "01-Jan-05" it does not sort properly with my sort routine: function compareDate(a,b) { var date_a = new Date(a); var date_b = new Date(b); if (date_a < date_b)...
2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
20
by: Xah Lee | last post by:
Sort a List Xah Lee, 200510 In this page, we show how to sort a list in Python & Perl and also discuss some math of sort. To sort a list in Python, use the “sort” method. For example: ...
2
by: Gernot Frisch | last post by:
Hi, I know I can give a std::map a sorting function in the c'tor. However, I would need to _change_ the sorting behaviour of an existing instance. How would I do that? Thank you, --
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
20
by: martin-g | last post by:
Hi. Mostly I program in C++, and I'm not fluent in C# and .NET. In my last project I began to use LinkedList<and suddenly noticed that can't find a way to sort it. Does it mean I must implement...
7
by: abracadabra | last post by:
I am reading an old book - Programming Pearls 2nd edition recently. It says, "Even though the general C++ program uses 50 times the memory and CPU time of the specialized C program, it requires...
4
by: arnuld | last post by:
This program follows from the section 6.5 of K&R2 where authors created a doubly-linked list using a binary-tree based approach. The only thing I have rewritten myself is the getword function. I am...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.