串的顺序存储结构-字符串的比较
//比较两个串 1本串大  -1 s串大  0相等
public int Compare(StringList s) {
    int sounceLength = this.Length();
    int length = s.Length();
    int i = 0;
    int j = 0;
    char c = '\0';

    while (i < sounceLength && j < length) {
        s.GetCharByIndex(j + 1, ref c);
        if (this._data[i] > c) {
            return 1;
        }

        if (this._data[i] < c) {
            return -1;
        }

        i++;
        j++;
    }

    if (sounceLength == length)
    {
        return 0;
    }

    if (sounceLength > length) {
        return 1;
    }

    return -1;
}



首页 我的博客
粤ICP备17103704号