Skip to main content

โฌ…๏ธ Back

Returns the last element of the array (the oldest element added).

๐Ÿ“ Syntaxโ€‹

TypeOfArray back()

๐Ÿ”ฎ Exampleโ€‹

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

// Will return 0
intAverage.back();

// Array: 8 0 0 0
intAverage.push(8);
// Array: 7 8 0 0
intAverage.push(7);
// Array: 12 7 8 0
intAverage.push(12);
// Array: 1 12 7 8
intAverage.push(1);

// Will return 8
intAverage.back();

โฑ Complexityโ€‹

Constant (O(1)).