From e386a8063b3fa83b026f4850fa9868acdbf0bc08 Mon Sep 17 00:00:00 2001 From: karol Date: Thu, 19 Jun 2025 00:28:19 +0200 Subject: [PATCH 1/2] Added sort implementation --- homework/length-sort/sort.cpp | 12 ++++++++++++ homework/length-sort/sort.hpp | 10 ++++++++++ 2 files changed, 22 insertions(+) create mode 100644 homework/length-sort/sort.cpp create mode 100644 homework/length-sort/sort.hpp diff --git a/homework/length-sort/sort.cpp b/homework/length-sort/sort.cpp new file mode 100644 index 000000000..063824395 --- /dev/null +++ b/homework/length-sort/sort.cpp @@ -0,0 +1,12 @@ +#include "sort.hpp" +#include + +std::deque lengthSort(std::forward_list& fl) +{ + std::deque dq{fl.begin(), fl.end()}; + + std::sort(dq.begin(), dq.end()); + std::sort(dq.begin(), dq.end(), [](const std::string& a, const std::string& b){ return a.size() < b.size();}); + + return dq; +} \ No newline at end of file diff --git a/homework/length-sort/sort.hpp b/homework/length-sort/sort.hpp new file mode 100644 index 000000000..f8a29b6dd --- /dev/null +++ b/homework/length-sort/sort.hpp @@ -0,0 +1,10 @@ +#ifndef SORT_HPP +#define SORT_HPP + +#include +#include +#include + +std::deque lengthSort(std::forward_list& fl); + +#endif \ No newline at end of file From e045a47fa714966d9f78bde2e00326d5fa78329c Mon Sep 17 00:00:00 2001 From: karol Date: Thu, 19 Jun 2025 00:30:05 +0200 Subject: [PATCH 2/2] Fixed formating --- homework/length-sort/sort.cpp | 5 ++--- homework/length-sort/sort.hpp | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/homework/length-sort/sort.cpp b/homework/length-sort/sort.cpp index 063824395..a9505c779 100644 --- a/homework/length-sort/sort.cpp +++ b/homework/length-sort/sort.cpp @@ -1,12 +1,11 @@ #include "sort.hpp" #include -std::deque lengthSort(std::forward_list& fl) -{ +std::deque lengthSort(std::forward_list& fl) { std::deque dq{fl.begin(), fl.end()}; std::sort(dq.begin(), dq.end()); - std::sort(dq.begin(), dq.end(), [](const std::string& a, const std::string& b){ return a.size() < b.size();}); + std::sort(dq.begin(), dq.end(), [](const std::string& a, const std::string& b) { return a.size() < b.size(); }); return dq; } \ No newline at end of file diff --git a/homework/length-sort/sort.hpp b/homework/length-sort/sort.hpp index f8a29b6dd..4a3b8ffce 100644 --- a/homework/length-sort/sort.hpp +++ b/homework/length-sort/sort.hpp @@ -2,8 +2,8 @@ #define SORT_HPP #include -#include #include +#include std::deque lengthSort(std::forward_list& fl);