3.1.22

3.1.22 #

解答 #

Get() 做修改,得到 MoveToFrontArrayST

public TValue Get(TKey key)
{
    int i;
    for (i = 0; i < _n; i++)
        if (_keys[i].Equals(key))
            break;

    if (i == _n)
        return default;

    var toFrontKey = _keys[i];
    var toFrontValue = _values[i];

    for (var j = i; j > 0; j--)
        _keys[j] = _keys[j - 1];
    for (var j = i; j > 0; j--)
        _values[j] = _values[j - 1];

    _keys[0] = toFrontKey;
    _values[0] = toFrontValue;

    return _values[0];
}

另请参阅 #

SymbolTable 库