mirror of
https://github.com/Ladebeze66/cpp-partie-2.git
synced 2025-12-15 21:56:55 +01:00
cpp0902
This commit is contained in:
parent
36bc6ff6b3
commit
bc0c76ac99
@ -6,7 +6,7 @@
|
||||
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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 :
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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>
|
||||
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<typename Container>
|
||||
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<double>(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<double>(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<int> et std::list<int>
|
||||
template void PmergeMe::fordJohnsonLikeSort<std::vector<int> >(std::vector<int>&, std::vector<int>::iterator, std::vector<int>::iterator);
|
||||
|
||||
@ -6,17 +6,17 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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] << " <sequence of integers>" << std::endl;
|
||||
std::cerr << RED << "Usage: " << argv[0] << " <sequence of integers>" << 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<int>..." << std::endl;
|
||||
std::cout << ORANGE << "Processing with std::vector<int>..." << RESET << std::endl;
|
||||
pmerge.sortAndDisplay(vectorInput);
|
||||
|
||||
// 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);
|
||||
|
||||
return (0);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user