5180 fichiers 38.5 Mo 0 téléchargements 182 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / api / utils / FixedSizeStack.ts
FixedSizeStack.ts 1.1 Ko Télécharger le fichier
export class FixedSizeStack {
    private _data: number[];
    private _maxSize: number;
    private _index: number;

    constructor(k: number) {
        this._data = [];
        this._maxSize = k;
        this._index = 0;
    }

    public reset(): void {
        this._data = [];
        this._index = 0;
    }

    public addValue(k: number): void {
        if (this._data.length < this._maxSize) {
            this._data.push(k);
        } else {
            this._data[this._index] = k;
        }

        this._index = (this._index + 1) % this._maxSize;
    }

    public getMax(): number {
        let k = Number.MIN_VALUE;

        let _local_2 = 0;

        while (_local_2 < this._maxSize) {
            if (this._data[_local_2] > k) k = this._data[_local_2];

            _local_2++;
        }

        return k;
    }

    public getMin(): number {
        let k = Number.MAX_VALUE;

        let _local_2 = 0;

        while (_local_2 < this._maxSize) {
            if (this._data[_local_2] < k) k = this._data[_local_2];

            _local_2++;
        }

        return k;
    }
}
15Sujets
1Dépôts
20Membres
2En ligne
Profile
Inscrit
Dernière visite
Messages
0
Votes positifs
0
Votes négatifs
0

Nous utilisons des cookies pour assurer le bon fonctionnement du site et améliorer votre expérience. en savoir plus

Autoriser