This commit is contained in:
2024-03-16 17:25:56 +01:00
parent 8a57eedbd6
commit 1646901adb
13 changed files with 176 additions and 52 deletions

View File

@@ -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/08 14:08:06 by fgras-ca ### ########.fr */
/* Updated: 2024/03/16 16:28:26 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -102,6 +102,4 @@ template void PmergeMe::displaySequence<std::vector<int> >(const std::vector<int
template void PmergeMe::displaySequence<std::list<int> >(const std::list<int>&, const std::string&);
template void PmergeMe::measureAndSort<std::vector<int> >(std::vector<int>&, const std::string&);
// Spécialisation explicite pour std::list<int>
template void PmergeMe::measureAndSort<std::list<int> >(std::list<int>&, const std::string&);

View File

@@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 16:17:28 by fgras-ca #+# #+# */
/* Updated: 2024/03/07 14:00:07 by fgras-ca ### ########.fr */
/* Updated: 2024/03/16 17:07:11 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -21,6 +21,8 @@
#include <algorithm> // Pour les conteneurs supportant le tri direct
#include <iterator> // Pour std::distance et std::advance
#include <cstdlib> // Pour std::atoi
#include <climits>
#include <cerrno>
#define RESET "\033[0m"
#define BLACK "\033[30m"

View File

@@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/07 13:25:02 by fgras-ca #+# #+# */
/* Updated: 2024/03/08 13:50:25 by fgras-ca ### ########.fr */
/* Updated: 2024/03/16 17:10:14 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -24,24 +24,24 @@ int main(int argc, char **argv)
std::vector<int> vectorInput;
std::list<int> listInput;
// Remplir les conteneurs avec les entiers fournis en arguments
for(int i = 1; i < argc; ++i)
{
int value = std::atoi(argv[i]);
if(value < 0)
errno = 0; // Réinitialiser errno avant la conversion
char* endPtr;
long value = std::strtol(argv[i], &endPtr, 10);
// Vérifier si la conversion a réussi et que toute la chaîne a été consommée
if (*endPtr != '\0' || errno == ERANGE || value < 0 || value > INT_MAX)
{
std::cerr << RED << "Error: Only positive integers are allowed." << RESET << std::endl;
std::cerr << RED << "Error: Argument \"" << argv[i] << "\" is not a valid positive integer or it is out of the int range." << RESET << std::endl;
return (1);
}
vectorInput.push_back(value);
listInput.push_back(value);
vectorInput.push_back(static_cast<int>(value));
listInput.push_back(static_cast<int>(value));
}
// Traitement et affichage pour std::vector
std::cout << ORANGE << "Processing with std::vector<int>..." << RESET << std::endl;
pmerge.sortAndDisplay(vectorInput);
// Traitement et affichage pour std::list
std::cout << ORANGE << "\nProcessing with std::list<int>..." << RESET << std::endl;
pmerge.sortAndDisplay(listInput);