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
lexicographically
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?
You could simply do:
var parts = new List<string>();
for (int i = 0; i < word.Length; i++)
parts.Add(word.Substring(i));
parts.Sort();
The output should be as you expect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With