From 97b4d62734acf7533a96b08bcc6044eb94847931 Mon Sep 17 00:00:00 2001 From: Justsvetoslavov Date: Thu, 13 Jan 2022 21:15:47 +0200 Subject: Add Pract. solutions. --- pract_SI/Pract. 09/task6.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 pract_SI/Pract. 09/task6.cpp (limited to 'pract_SI/Pract. 09/task6.cpp') diff --git a/pract_SI/Pract. 09/task6.cpp b/pract_SI/Pract. 09/task6.cpp new file mode 100644 index 0000000..a380fb2 --- /dev/null +++ b/pract_SI/Pract. 09/task6.cpp @@ -0,0 +1,18 @@ +#include + +void insertIntoVector(std::vector& arr, int number, int index) +{ + if (arr.empty() || arr.size() <= index) //insert @end + { + arr.push_back(number); + return; + } + + if (arr[index] > number) + { + arr.insert(arr.begin() + index, number); + return; + } + + return insertIntoVector(arr, number, ++index); +} -- cgit v1.3.1-23-gd82d