Skip to main content

📍 AtIndex

Returns the requested element at the absolute position of the array.

If the requested index exceed the array size, it will return a 0.

📝 Syntax

TypeOfArray at_index(size_t index)

🔮 Example

// This will create an MovingAverage of size 4 and int type
MovingAveragePlus<int> intAverage(4);

// Array.atIndex(): 1 0 0 0
intAverage.push(1);
// Array.atIndex(): 1 2 0 0
intAverage.push(2);
// Array.atIndex(): 1 2 3 0
intAverage.push(3);
// Array.atIndex(): 1 2 3 4
intAverage.push(4)

// return 1
intAverage.at_index(0);

⏱ Complexity

Constant (O(1)).