[Solved] Sort array contains numeric string using c# array


You need give an order (actually a equivalence relation) to be able to sort. The order on characters is usually a,b,c,… and the order usually given on words such as ‘one’ is called lexicographic order. However you want to sort by the meaning behind, its semantic: integers.

Your computer doesn’t know that you want this, so you need to provide the meaning., which is through a function (technically a dictionary).

Computers have order on integers builtin (it’s also builtin in standard integers, in usual mathematics). Hence you need to provide a one-to-one function (eg., with a dictionary, or a list of uples eg., List<(string, int)>), so you sort your words from their integer peer. You can also map words with letters: one-a, two-b, … and when you reach z, you continue with aa (it’s a base 27 counting). You can also do this with bits (base 2), base64, etc. But there is always a map with integers.

IMHO, understanding is more important than knowing. Now you can code many solutions.

solved Sort array contains numeric string using c# array