Fraiser Fraiser - 1 year ago 100
C# Question

Lexicographical sort algorithm using C#

I am struggling to write a sorting algorithm that can sort characters in a word lexicographically (alphabetically) as follows

lexicographical sort of the word :- Contamination


Sorted Text               Index

------------------         ----------

amination                      0

ation                              1

contamination                2

ination                            3

ion                                  4

mination                          5

n                                    6

nation                            7

ntamination                    8

on                                  9

ontamination                  10

tamination                       11

tion                                12

Could anyone please help write a pseudo code / or an implementation in C# or VB.NET of how I can do a lexicographical sort of the word above?

Answer Source
string str = "contamination";
IEnumerable<string> sortedSubstrings =
    Enumerable.Range(0, str.Length)
              .Select(i => str.Substring(i))
              .OrderBy(s => s);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download