Answer the question
In order to leave comments, you need to log in
How to sort without strings when sorting an array of strings?
There is an array of strings
. You need to sort it and take the last character from each string.
These strings are generated according to the algorithm: the last character is moved to the first place.
I thought that it might be possible not to store them somehow, but simply to take the last character from the generated string and the code by which it would then be possible to sort the last characters that I took.
line code and its last character
public class Element
{
public char Symbol;
public int Hash;
public static Element Create(StringBuilder str)
{
int code = 0;
//как нибудь считается этот код)
for (int i = 0; i < str.Length; i++)
{
code +=(str[i] - 'a'+ 1) * (str.Length - i) + 127 *(str.Length - i);
}
return new Element { Symbol = str[str.Length - 1], Hash = code};
}
}
for (int i = 0; i < strL; i++)
{
curStr.Insert(0, curStr[strL - 1]);
curStr.Remove(strL, 1);
list.Add(Element.Create(curStr));
}
Answer the question
In order to leave comments, you need to log in
That's what I did
private class VirtualStringBWT : IComparable<VirtualStringBWT>, IEnumerable<char>
{
char[] _sourse;
int _shiftRight;
public VirtualStringBWT(char[] sourse, int shift)
{
if (shift >= sourse.Length)
throw new ArgumentOutOfRangeException("Нельзя сдвигать на число большее или равное количеству символов!");
_sourse = sourse;
_shiftRight = shift;
}
public int CompareTo(VirtualStringBWT other)
{
if (other == null)
throw new NullReferenceException();
IEnumerator<char> thisEnumerator = this.GetEnumerator();
IEnumerator<char> otherEnumerator = other.GetEnumerator();
//строки одинаковой длины
while (thisEnumerator.MoveNext() && otherEnumerator.MoveNext())
{
if (thisEnumerator.Current > otherEnumerator.Current)
return 1;
else if (thisEnumerator.Current < otherEnumerator.Current)
return -1;
}
return 0;
}
public IEnumerator<char> GetEnumerator()
{
int startI = _sourse.Length - _shiftRight;
int i = startI;
while (i < _sourse.Length)
{
yield return _sourse[i];
i++;
}
i = 0;
while (i < startI)
{
yield return _sourse[i];
i++;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}
for (int i = 0; i < _source.Length; i++)
list.Add(new VirtualStringBWT(t, i));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question