3.1.22

上次更新:2019-04-17
发现了题解错误/代码缺陷/排版问题?请点这里:如何:提交反馈

解答

Get() 做修改,得到 MoveToFrontArrayST

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

    if (i == this.n)
        return default(TValue);

    TKey toFrontKey = this.keys[i];
    TValue toFrontValue = this.values[i];

    for (int j = i; j > 0; j--)
        this.keys[j] = this.keys[j - 1];
    for (int j = i; j > 0; j--)
        this.values[j] = this.values[j - 1];

    this.keys[0] = toFrontKey;
    this.values[0] = toFrontValue;

    return this.values[0];
}

另请参阅

SymbolTable 库

上一题 下一题