58 lines
1.1 KiB
C++
58 lines
1.1 KiB
C++
#include "PmergeMe.hpp"
|
|
|
|
PmergeMe::PmergeMe()
|
|
{
|
|
}
|
|
|
|
PmergeMe::PmergeMe(const PmergeMe &other)
|
|
{
|
|
this->_vec = other._vec;
|
|
this->_deq = other._deq;
|
|
}
|
|
|
|
PmergeMe &PmergeMe::operator=(const PmergeMe &other)
|
|
{
|
|
this->_vec = other._vec;
|
|
this->_deq = other._deq;
|
|
return (*this);
|
|
}
|
|
|
|
PmergeMe::~PmergeMe()
|
|
{
|
|
}
|
|
|
|
void PmergeMe::printDeque() const
|
|
{
|
|
for (std::deque<int>::const_iterator it = _deq.begin(); it != _deq.end(); ++it)
|
|
std::cout << *it << " ";
|
|
std::cout << std::endl;
|
|
}
|
|
|
|
void PmergeMe::printVector() const
|
|
{
|
|
for (std::vector<int>::const_iterator it = _vec.begin(); it != _vec.end(); ++it)
|
|
std::cout << *it << " ";
|
|
std::cout << std::endl;
|
|
}
|
|
|
|
void PmergeMe::parseInput(int ac, char **av)
|
|
{
|
|
std::string token;
|
|
int n;
|
|
|
|
for (int i = 1; i < ac; i++) {
|
|
std::istringstream ss(av[i]);
|
|
while (ss >> token) {
|
|
std::istringstream iss(token);
|
|
if (!(iss >> n) || !iss.eof() || n < 0)
|
|
throw std::runtime_error("Error");
|
|
if (std::find(_vec.begin(), _vec.end(), n) != _vec.end())
|
|
throw std::runtime_error("Error");
|
|
_vec.push_back(n);
|
|
_deq.push_back(n);
|
|
}
|
|
}
|
|
if (_vec.empty())
|
|
throw std::runtime_error("Error");
|
|
}
|