22Span::Span(
unsigned int N) : _maxSize(N) {
27Span::Span(
const Span &other) : _maxSize(other._maxSize), _numbers(other._numbers) {}
32 _numbers.
swap(other._numbers);
46 if (_numbers.
size() >= _maxSize) {
54 if (_numbers.
size() <= 1) {
64 for (
size_t i = 1; i < sorted.
size(); ++i) {
65 long currentSpan =
static_cast<long>(sorted[i]) -
static_cast<long>(sorted[i - 1]);
66 if (currentSpan < minSpan) {
67 minSpan = currentSpan;
70 return static_cast<int>(minSpan);
75 if (_numbers.
size() <= 1) {
83 return maxVal - minVal;
Provides a class that stores N integers and calculates their shortest and longest spans.
An exception thrown when there are insufficient numbers to calculate the span.
Exception thrown when Span is full.
A class that stores up to N integers and calculates the shortest and longest spans.
void swap(Span &other)
Swaps the contents of two Span objects.
int shortestSpan()
Calculates the shortest span between stored numbers.
int longestSpan()
Calculates the longest span between stored numbers.
Span & operator=(Span other)
Assignment operator (copy-and-swap idiom).
void addNumber(int number)
Adds a single number to the span.