diff --git a/ex00/BitcoinExchange.cpp b/ex00/BitcoinExchange.cpp index 272ed92..ca6a599 100644 --- a/ex00/BitcoinExchange.cpp +++ b/ex00/BitcoinExchange.cpp @@ -13,8 +13,6 @@ Date::Date(void) Date::Date(std::string str) { - // check format (4 char & isdigit into dash into 2 char isdigit & < 1 && isdigit & < 2, and same for day except ahah funny cuz 30 and 31 and 28 and 29 agfjasfgfjahkfga) - _value = 0; for (size_t i = 0; str[i]; ++i) { if (!isdigit(str[i]) && !((i == (str.length() - 6) || i == (str.length() - 3)) && str[i] == '-')) @@ -23,6 +21,8 @@ Date::Date(std::string str) throw std::invalid_argument("invalid date."); } } + + _value = 0; for (std::string::iterator it = str.begin(); it < str.end(); ++it) { if (!isdigit(*it)) diff --git a/ex00/input.txt b/ex00/input.txt index 96d7b85..036082f 100644 --- a/ex00/input.txt +++ b/ex00/input.txt @@ -1,4 +1,5 @@ date | value +2002.01-2 | 5 1971-01-02 | 5 1971-31-02 | 5 2011-01-03 | 3 diff --git a/ex02/Makefile b/ex02/Makefile index 7610cf1..9de7fea 100644 --- a/ex02/Makefile +++ b/ex02/Makefile @@ -6,7 +6,7 @@ # By: mmoussou generateJacobsthal(size_t n) +{ + std::vector seq; + if (n == 0) + return seq; + seq.push_back(0); + if (n == 1) + return seq; + seq.push_back(1); + size_t j0 = 0, j1 = 1; + while (true) + { + size_t jn = j1 + 2 * j0; + if (jn >= n) + break; + seq.push_back(jn); + j0 = j1; + j1 = jn; + } + return seq; +} diff --git a/ex02/PmergeMe.hpp b/ex02/PmergeMe.hpp index 2b5eb6a..d678484 100644 --- a/ex02/PmergeMe.hpp +++ b/ex02/PmergeMe.hpp @@ -11,27 +11,7 @@ #include #include -std::vector generateJacobsthal(size_t n) -{ - std::vector seq; - if (n == 0) - return seq; - seq.push_back(0); - if (n == 1) - return seq; - seq.push_back(1); - size_t j0 = 0, j1 = 1; - while (true) - { - size_t jn = j1 + 2 * j0; - if (jn >= n) - break; - seq.push_back(jn); - j0 = j1; - j1 = jn; - } - return seq; -} +std::vector generateJacobsthal(size_t n); template typename Container::iterator binaryInsertPosition(Container &c, const T &value) @@ -41,7 +21,7 @@ typename Container::iterator binaryInsertPosition(Container &c, const T &value) while (first < last) { - typename Container::iterator mid = first + (last - first) / 2; //tzvetan told me a better way iirc but i don't remember D: + typename Container::iterator mid = first + (last - first) / 2; if (*mid < value) first = mid + 1; else diff --git a/ex02/main.cpp b/ex02/main.cpp index c1172f6..08465e6 100644 --- a/ex02/main.cpp +++ b/ex02/main.cpp @@ -43,7 +43,7 @@ int main(int argc, char **argv) for (size_t i = 0; i < vec.size() && i < 6; i++) std::cout << vec[i] << " "; if (vec.size() > 6) - std::cout << "[...]"; + std::cout << "[...] (" << vec.size() << ")"; std::cout << std::endl; clock_t startVec = clock(); @@ -58,9 +58,14 @@ int main(int argc, char **argv) for (size_t i = 0; i < vec.size() && i < 6; i++) std::cout << vec[i] << " "; if (vec.size() > 6) - std::cout << "[...]"; + std::cout << "[...] (" << vec.size() << ")"; std::cout << std::endl; + std::vector sortedVec = vec; + std::sort(sortedVec.begin(), sortedVec.end()); + if (vec != sortedVec) + throw std::runtime_error("it's not sorted, what-"); + double vecTime = (double)(endVec - startVec) / CLOCKS_PER_SEC * 1000000.0; double deqTime = (double)(endDeq - startDeq) / CLOCKS_PER_SEC * 1000000.0;