chenyc
2025-12-09 65e034683b28d799e73c7d7e5e4769fab5b9bc9c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { Container } from "../../ContainerBase";
declare abstract class SequentialContainer<T> extends Container<T> {
    /**
     * @description Push the element to the back.
     * @param element - The element you want to push.
     * @returns The size of container after pushing.
     */
    abstract pushBack(element: T): number;
    /**
     * @description Removes the last element.
     * @returns The element you popped.
     */
    abstract popBack(): T | undefined;
    /**
     * @description Sets element by position.
     * @param pos - The position you want to change.
     * @param element - The element's value you want to update.
     * @example
     * container.setElementByPos(-1, 1); // throw a RangeError
     */
    abstract setElementByPos(pos: number, element: T): void;
    /**
     * @description Removes the elements of the specified value.
     * @param value - The value you want to remove.
     * @returns The size of container after erasing.
     * @example
     * container.eraseElementByValue(-1);
     */
    abstract eraseElementByValue(value: T): number;
    /**
     * @description Insert several elements after the specified position.
     * @param pos - The position you want to insert.
     * @param element - The element you want to insert.
     * @param num - The number of elements you want to insert (default 1).
     * @returns The size of container after inserting.
     * @example
     * const container = new Vector([1, 2, 3]);
     * container.insert(1, 4);  // [1, 4, 2, 3]
     * container.insert(1, 5, 3); // [1, 5, 5, 5, 4, 2, 3]
     */
    abstract insert(pos: number, element: T, num?: number): number;
    /**
     * @description Reverses the container.
     * @example
     * const container = new Vector([1, 2, 3]);
     * container.reverse(); // [3, 2, 1]
     */
    abstract reverse(): void;
    /**
     * @description Removes the duplication of elements in the container.
     * @returns The size of container after inserting.
     * @example
     * const container = new Vector([1, 1, 3, 2, 2, 5, 5, 2]);
     * container.unique(); // [1, 3, 2, 5, 2]
     */
    abstract unique(): number;
    /**
     * @description Sort the container.
     * @param cmp - Comparison function to sort.
     * @example
     * const container = new Vector([3, 1, 10]);
     * container.sort();  // [1, 10, 3]
     * container.sort((x, y) => x - y); // [1, 3, 10]
     */
    abstract sort(cmp?: (x: T, y: T) => number): void;
}
export default SequentialContainer;