From bc0c76ac99bf019fee263dd618fb6191b26a7af6 Mon Sep 17 00:00:00 2001 From: Ladebeze66 Date: Fri, 8 Mar 2024 14:12:36 +0100 Subject: [PATCH] cpp0902 --- cpp09/ex02/Makefile | 6 +++--- cpp09/ex02/PmergeMe.cpp | 23 ++++++++++++----------- cpp09/ex02/main.cpp | 12 ++++++------ 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/cpp09/ex02/Makefile b/cpp09/ex02/Makefile index c9cae49..cb034c2 100644 --- a/cpp09/ex02/Makefile +++ b/cpp09/ex02/Makefile @@ -6,7 +6,7 @@ # By: fgras-ca +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/12/27 20:57:42 by fgras-ca #+# #+# # -# Updated: 2024/03/06 15:58:19 by fgras-ca ### ########.fr # +# Updated: 2024/03/08 14:09:35 by fgras-ca ### ########.fr # # # # **************************************************************************** # @@ -23,7 +23,7 @@ CYAN = \033[0;96m WHITE = \033[0;97m ORANGE = \033[38;5;214m -NAME = pmergeme +NAME = PmergeMe SRC = main.cpp \ PmergeMe.cpp \ @@ -41,7 +41,7 @@ all : $(NAME) $(NAME) : $(OBJS) @echo "$(RED)Compilation fixed... $(DEF_COLOR)" $(CC) $(CFLAGS) $(OBJS) -g -o $(NAME) - @echo "$(GREEN)Compilation complete. $(ORANGE)Type "./pmergeme" to execute the program!!$(DEF_COLOR)" + @echo "$(GREEN)Compilation complete. $(ORANGE)Type "./PmergeMe" to execute the program!!$(DEF_COLOR)" $(LOGO) clean : diff --git a/cpp09/ex02/PmergeMe.cpp b/cpp09/ex02/PmergeMe.cpp index 62709fb..88a908f 100644 --- a/cpp09/ex02/PmergeMe.cpp +++ b/cpp09/ex02/PmergeMe.cpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/07 13:12:20 by fgras-ca #+# #+# */ -/* Updated: 2024/03/07 14:04:03 by fgras-ca ### ########.fr */ +/* Updated: 2024/03/08 14:08:06 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,7 +71,7 @@ void PmergeMe::fordJohnsonLikeSort(Container& container, typename Container::ite template void PmergeMe::displaySequence(const Container& sequence, const std::string& prefix) { - std::cout << prefix << ": "; + std::cout << RED << prefix << ": " << RESET; for (typename Container::const_iterator it = sequence.begin(); it != sequence.end(); ++it) { std::cout << *it << " "; @@ -80,18 +80,19 @@ void PmergeMe::displaySequence(const Container& sequence, const std::string& pre } // Mesure du temps de tri et affichage template -void PmergeMe::measureAndSort(Container& container, const std::string& containerName) { - displaySequence(container, "Before"); +void PmergeMe::measureAndSort(Container& container, const std::string& containerName) +{ + displaySequence(container, "Before"); - std::clock_t start = std::clock(); - fordJohnsonLikeSort(container, container.begin(), container.end()); - std::clock_t end = std::clock(); + std::clock_t start = std::clock(); + fordJohnsonLikeSort(container, container.begin(), container.end()); + std::clock_t end = std::clock(); - displaySequence(container, "After"); + displaySequence(container, "After"); - double duration = static_cast(end - start) / CLOCKS_PER_SEC * 1000000; // Convertir en microsecondes - std::cout << "Time to process a range of " << container.size() - << " elements with " << containerName << " : " << duration << " us\n"; + double duration = static_cast(end - start) / CLOCKS_PER_SEC * 1000000; // Convertir en microsecondes + std::cout << CYAN << "Time to process a range of " << container.size() + << " elements with " << containerName << " : " << duration << " us\n" << RESET; } // Spécialisations explicites pour std::vector et std::list template void PmergeMe::fordJohnsonLikeSort >(std::vector&, std::vector::iterator, std::vector::iterator); diff --git a/cpp09/ex02/main.cpp b/cpp09/ex02/main.cpp index 431b5ff..5dd60a0 100644 --- a/cpp09/ex02/main.cpp +++ b/cpp09/ex02/main.cpp @@ -6,17 +6,17 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/07 13:25:02 by fgras-ca #+# #+# */ -/* Updated: 2024/03/07 13:56:19 by fgras-ca ### ########.fr */ +/* Updated: 2024/03/08 13:50:25 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #include "PmergeMe.hpp" -int main(int argc, char* argv[]) +int main(int argc, char **argv) { if(argc < 2) { - std::cerr << "Usage: " << argv[0] << " " << std::endl; + std::cerr << RED << "Usage: " << argv[0] << " " << RESET << std::endl; return (1); } @@ -30,7 +30,7 @@ int main(int argc, char* argv[]) int value = std::atoi(argv[i]); if(value < 0) { - std::cerr << "Error: Only positive integers are allowed." << std::endl; + std::cerr << RED << "Error: Only positive integers are allowed." << RESET << std::endl; return (1); } vectorInput.push_back(value); @@ -38,11 +38,11 @@ int main(int argc, char* argv[]) } // Traitement et affichage pour std::vector - std::cout << "Processing with std::vector..." << std::endl; + std::cout << ORANGE << "Processing with std::vector..." << RESET << std::endl; pmerge.sortAndDisplay(vectorInput); // Traitement et affichage pour std::list - std::cout << "\nProcessing with std::list..." << std::endl; + std::cout << ORANGE << "\nProcessing with std::list..." << RESET << std::endl; pmerge.sortAndDisplay(listInput); return (0);