This commit is contained in:
Ladebeze66 2024-03-08 14:12:36 +01:00
parent 36bc6ff6b3
commit bc0c76ac99
3 changed files with 21 additions and 20 deletions

View File

@ -6,7 +6,7 @@
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ # # By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/12/27 20:57:42 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 WHITE = \033[0;97m
ORANGE = \033[38;5;214m ORANGE = \033[38;5;214m
NAME = pmergeme NAME = PmergeMe
SRC = main.cpp \ SRC = main.cpp \
PmergeMe.cpp \ PmergeMe.cpp \
@ -41,7 +41,7 @@ all : $(NAME)
$(NAME) : $(OBJS) $(NAME) : $(OBJS)
@echo "$(RED)Compilation fixed... $(DEF_COLOR)" @echo "$(RED)Compilation fixed... $(DEF_COLOR)"
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME) $(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) $(LOGO)
clean : clean :

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */ /* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/07 13:12:20 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<typename Container> template<typename Container>
void PmergeMe::displaySequence(const Container& sequence, const std::string& prefix) 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) for (typename Container::const_iterator it = sequence.begin(); it != sequence.end(); ++it)
{ {
std::cout << *it << " "; std::cout << *it << " ";
@ -80,7 +80,8 @@ void PmergeMe::displaySequence(const Container& sequence, const std::string& pre
} }
// Mesure du temps de tri et affichage // Mesure du temps de tri et affichage
template<typename Container> template<typename Container>
void PmergeMe::measureAndSort(Container& container, const std::string& containerName) { void PmergeMe::measureAndSort(Container& container, const std::string& containerName)
{
displaySequence(container, "Before"); displaySequence(container, "Before");
std::clock_t start = std::clock(); std::clock_t start = std::clock();
@ -90,8 +91,8 @@ void PmergeMe::measureAndSort(Container& container, const std::string& container
displaySequence(container, "After"); displaySequence(container, "After");
double duration = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000000; // Convertir en microsecondes double duration = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000000; // Convertir en microsecondes
std::cout << "Time to process a range of " << container.size() std::cout << CYAN << "Time to process a range of " << container.size()
<< " elements with " << containerName << " : " << duration << " us\n"; << " elements with " << containerName << " : " << duration << " us\n" << RESET;
} }
// Spécialisations explicites pour std::vector<int> et std::list<int> // Spécialisations explicites pour std::vector<int> et std::list<int>
template void PmergeMe::fordJohnsonLikeSort<std::vector<int> >(std::vector<int>&, std::vector<int>::iterator, std::vector<int>::iterator); template void PmergeMe::fordJohnsonLikeSort<std::vector<int> >(std::vector<int>&, std::vector<int>::iterator, std::vector<int>::iterator);

View File

@ -6,17 +6,17 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */ /* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/07 13:25:02 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" #include "PmergeMe.hpp"
int main(int argc, char* argv[]) int main(int argc, char **argv)
{ {
if(argc < 2) if(argc < 2)
{ {
std::cerr << "Usage: " << argv[0] << " <sequence of integers>" << std::endl; std::cerr << RED << "Usage: " << argv[0] << " <sequence of integers>" << RESET << std::endl;
return (1); return (1);
} }
@ -30,7 +30,7 @@ int main(int argc, char* argv[])
int value = std::atoi(argv[i]); int value = std::atoi(argv[i]);
if(value < 0) 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); return (1);
} }
vectorInput.push_back(value); vectorInput.push_back(value);
@ -38,11 +38,11 @@ int main(int argc, char* argv[])
} }
// Traitement et affichage pour std::vector // Traitement et affichage pour std::vector
std::cout << "Processing with std::vector<int>..." << std::endl; std::cout << ORANGE << "Processing with std::vector<int>..." << RESET << std::endl;
pmerge.sortAndDisplay(vectorInput); pmerge.sortAndDisplay(vectorInput);
// Traitement et affichage pour std::list // Traitement et affichage pour std::list
std::cout << "\nProcessing with std::list<int>..." << std::endl; std::cout << ORANGE << "\nProcessing with std::list<int>..." << RESET << std::endl;
pmerge.sortAndDisplay(listInput); pmerge.sortAndDisplay(listInput);
return (0); return (0);