From 4e3c2596416f55ffc885ad867e87c86c88e0042e Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 2 May 2022 21:00:23 +0300 Subject: Autocommit at 02.05.2022 @ 21:00 --- src/List/List.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/List/List.cpp') diff --git a/src/List/List.cpp b/src/List/List.cpp index 617bbcf..7236616 100644 --- a/src/List/List.cpp +++ b/src/List/List.cpp @@ -43,10 +43,14 @@ void List::add(const T& element) { template bool List::insertAt(const T& element, unsigned index) { - if (index >= count) - return add(element); + if (index >= count) return add(element); + if (length == count) resize(); + for (unsigned i = count; i > index; i--) + elements[i] = elements[i - 1]; + elements[index] = element; + count++; } template -- cgit v1.3.1-23-gd82d