narnaud
2 years ago
52 changed files with 1348 additions and 782 deletions
@ -1,20 +1,21 @@ |
|||
NAME = bureau |
|||
SRCS = main.cpp Bureaucrat.cpp |
|||
OBJS= $(SRCS:.cpp=.o) |
|||
NAME = bureau |
|||
SRCS = main.cpp Bureaucrat.cpp |
|||
OBJS = $(SRCS:.cpp=.o) |
|||
|
|||
CXXFLAGS = -std=c++98 -Werror -Wextra -Wall |
|||
CXX = c++ |
|||
CXXFLAGS = -std=c++98 -Werror -Wextra -Wall |
|||
|
|||
$(NAME) : $(OBJS) |
|||
c++ $(OBJS) -o $(NAME) |
|||
$(NAME): $(OBJS) |
|||
$(CXX) $(CXXFLAGS) $(OBJS) -o $(NAME) |
|||
|
|||
all : $(NAME) |
|||
all: $(NAME) |
|||
|
|||
clean : |
|||
rm -rf $(OBJS) |
|||
clean: |
|||
rm -rf $(OBJS) |
|||
|
|||
fclean : clean |
|||
rm -rf $(NAME) |
|||
fclean: clean |
|||
rm -rf $(NAME) |
|||
|
|||
re : fclean all |
|||
re: fclean all |
|||
|
|||
.PHONY : all clean fclean re |
|||
.PHONY: all clean fclean re |
|||
|
@ -1,10 +0,0 @@ |
|||
,@@@@@@@, |
|||
,,,. ,@@@@@@/@@, .oo8888o. |
|||
,&%%&%&&%,@@@@@/@@@@@@,8888\88/8o |
|||
,%&\%&&%&&%,@@@\@@@/@@@88\88888/88' |
|||
%&&%&%&/%&&%@@\@@/ /@@@88888\88888' |
|||
%&&%/ %&%%&&@@\ V /@@' `88\8 `/88' |
|||
`&%\ ` /%&' |.| \ '|8' |
|||
|o| | | | | |
|||
|.| | | | | |
|||
\\/ ._\//_/__/ ,\_//__\\/. \_//__/_ |
@ -0,0 +1,18 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Data.h :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/09/29 09:28:26 by narnaud #+# #+# */ |
|||
/* Updated: 2022/09/29 09:28:45 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
#include <string> |
|||
|
|||
typedef struct s_Data { |
|||
std::string content; |
|||
} t_Data; |
@ -0,0 +1,19 @@ |
|||
|
|||
CXXFLAGS = -std=c++98 -Werror -Wextra -Wall |
|||
CXX = c++ |
|||
|
|||
serialize: main.o |
|||
$(CXX) $(CXXFLAGS) main.o -o serialize |
|||
|
|||
all: serialize |
|||
|
|||
clean: |
|||
rm -rf main.o |
|||
|
|||
fclean: clean |
|||
rm -rf serialize |
|||
|
|||
re: fclean all |
|||
|
|||
|
|||
.PHONY: all clean fclean re |
@ -0,0 +1,40 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud </var/spool/mail/narnaud> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/08/04 16:48:40 by narnaud #+# #+# */ |
|||
/* Updated: 2022/08/04 16:52:56 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Data.h" |
|||
#include "iostream" |
|||
#include "stdint.h" |
|||
|
|||
uintptr_t serialize(t_Data* ptr) { |
|||
return reinterpret_cast<uintptr_t>(ptr); |
|||
} |
|||
|
|||
t_Data* deserialize(uintptr_t raw) { |
|||
return reinterpret_cast<t_Data *>(raw); |
|||
} |
|||
|
|||
int main(void) { |
|||
t_Data * data = new t_Data; |
|||
uintptr_t raw; |
|||
t_Data * ptr; |
|||
|
|||
data->content = "Hi"; |
|||
raw = serialize(data); |
|||
ptr = deserialize(raw); |
|||
|
|||
std::cout |
|||
<< "Original content: " << data->content << std::endl |
|||
<< "Serialized: " << raw << std::endl |
|||
<< "Deserialized: " << ptr->content << std::endl; |
|||
delete data; |
|||
return (0); |
|||
} |
@ -0,0 +1,21 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* A.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/09/29 10:32:10 by narnaud #+# #+# */ |
|||
/* Updated: 2022/09/29 11:08:51 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include "Base.hpp" |
|||
|
|||
class A:public Base { |
|||
public: |
|||
A(void); |
|||
|
|||
}; |
@ -0,0 +1,19 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* B.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/09/29 10:33:17 by narnaud #+# #+# */ |
|||
/* Updated: 2022/09/29 11:09:17 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
#include "Base.hpp" |
|||
|
|||
class B:public Base { |
|||
public: |
|||
B(void); |
|||
}; |
@ -0,0 +1,19 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Base.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/09/29 10:30:30 by narnaud #+# #+# */ |
|||
/* Updated: 2022/09/29 11:09:47 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
class Base { |
|||
public: |
|||
Base(void); |
|||
virtual ~Base(void); |
|||
}; |
@ -0,0 +1,19 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* C.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/09/29 10:34:10 by narnaud #+# #+# */ |
|||
/* Updated: 2022/09/29 11:09:30 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
#include "Base.hpp" |
|||
|
|||
class C:public Base { |
|||
public: |
|||
C(void); |
|||
}; |
@ -0,0 +1,11 @@ |
|||
#include "Base.hpp" |
|||
#include "A.hpp" |
|||
#include "B.hpp" |
|||
#include "C.hpp" |
|||
|
|||
Base::Base(void){} |
|||
Base::~Base(void){} |
|||
|
|||
A::A(void){} |
|||
B::B(void){} |
|||
C::C(void){} |
@ -0,0 +1,17 @@ |
|||
CXX = c++ |
|||
CXXFLAGS = -std=c++98 -Werror -Wextra -Wall |
|||
|
|||
base: main.o Classes.o |
|||
$(CXX) $(CXXFLAGS) main.o Classes.o -o base |
|||
|
|||
all: base |
|||
|
|||
clean: |
|||
rm -rf main.o Classes.o |
|||
|
|||
fclean: clean |
|||
rm -rf base |
|||
|
|||
re: fclean all |
|||
|
|||
.PHONY: all clean fclean re |
@ -0,0 +1,90 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/09/29 10:09:08 by narnaud #+# #+# */ |
|||
/* Updated: 2022/09/29 10:36:06 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include <iostream> |
|||
#include <time.h> |
|||
#include <unistd.h> |
|||
#include <cstdlib> |
|||
#include "Base.hpp" |
|||
#include "A.hpp" |
|||
#include "B.hpp" |
|||
#include "C.hpp" |
|||
|
|||
Base *generate (void) { |
|||
int rand_id; |
|||
char names[3] = {'A', 'B', 'C'}; |
|||
std::srand(time(NULL) * std::rand()); |
|||
rand_id = std::rand() % 3; |
|||
std::cout << "Generated a " << names[rand_id] << std::endl; |
|||
switch (rand_id) { |
|||
case 0: |
|||
return new A; |
|||
break; |
|||
case 1: |
|||
return new B; |
|||
break; |
|||
case 2: |
|||
return new C; |
|||
break; |
|||
default: |
|||
return NULL; |
|||
} |
|||
} |
|||
|
|||
void identify(Base *ptr) { |
|||
A *a = dynamic_cast<A *>(ptr); |
|||
if (a) |
|||
std::cout << "Identified a A" << std::endl; |
|||
B *b = dynamic_cast<B *>(ptr); |
|||
if (b) |
|||
std::cout << "Identified a B" << std::endl; |
|||
C *c = dynamic_cast<C *>(ptr); |
|||
if (c) |
|||
std::cout << "Identified a C" << std::endl; |
|||
} |
|||
|
|||
void identify(Base &ref) { |
|||
try { |
|||
A a = dynamic_cast<A&>(ref); |
|||
std::cout << "Identified a A" << std::endl; |
|||
} |
|||
catch (std::exception &e) { (void)e;} |
|||
try { |
|||
B b = dynamic_cast<B &>(ref); |
|||
std::cout << "Identified a B" << std::endl; |
|||
} |
|||
catch (std::exception &e) { (void)e;} |
|||
try { |
|||
C c = dynamic_cast<C &>(ref); |
|||
std::cout << "Identified a C" << std::endl; |
|||
} |
|||
catch (std::exception &e) { (void)e;} |
|||
} |
|||
|
|||
int main(void) { |
|||
Base *ptr; |
|||
|
|||
std::cout << "Identify from pointer:" << std::endl; |
|||
for (int i = 0; i < 5; i++) { |
|||
ptr = generate(); |
|||
identify(ptr); |
|||
delete ptr; |
|||
} |
|||
|
|||
std::cout << "Identify from reference:" << std::endl; |
|||
for (int i = 0; i < 5; i++) { |
|||
ptr = generate(); |
|||
identify(*ptr); |
|||
delete ptr; |
|||
} |
|||
|
|||
} |
Binary file not shown.
@ -0,0 +1,35 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* easyfind.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/09/19 08:06:39 by narnaud #+# #+# */ |
|||
/* Updated: 2022/09/19 08:06:42 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include <algorithm> |
|||
#include <exception> |
|||
#include <iostream> |
|||
#include <iterator> |
|||
|
|||
template <class T> |
|||
typename T::iterator easyfind(T &t, const int nb) { |
|||
typename T::iterator it; |
|||
it = find(t.begin(), t.end(), nb); |
|||
if (it == t.end()) |
|||
return (t.end()); |
|||
return (it); |
|||
} |
|||
|
|||
template <class T> |
|||
void is_easyfound(T it, T end) { |
|||
if (it != end) |
|||
std::cout << "You found: " << *it << std::endl; |
|||
else |
|||
std::cout << "You didn't found it." << std::endl; |
|||
} |
@ -0,0 +1,43 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/09/19 08:06:21 by narnaud #+# #+# */ |
|||
/* Updated: 2022/09/19 08:06:26 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "easyfind.hpp" |
|||
#include <iostream> |
|||
#include <list> |
|||
#include <string> |
|||
#include <vector> |
|||
|
|||
int main(void) { |
|||
std::vector<int> tab; |
|||
std::vector<int>::iterator tab_it; |
|||
std::list<int> lst; |
|||
std::list<int>::iterator lst_it; |
|||
std::string str = "abcdefghijklmnopqrstuvwxyz\n"; |
|||
std::string::iterator str_it; |
|||
|
|||
tab.push_back(5); |
|||
tab.push_back(50); |
|||
lst.push_back(5); |
|||
lst.push_back(50); |
|||
|
|||
tab_it = easyfind(tab, 50); |
|||
lst_it = easyfind(lst, 50); |
|||
str_it = easyfind(str, 50); |
|||
|
|||
std::cout << "Array search:" << std::endl; |
|||
is_easyfound(tab_it, tab.end()); |
|||
std::cout << "List search:" << std::endl; |
|||
is_easyfound(lst_it, lst.end()); |
|||
std::cout << "String search" << std::endl; |
|||
is_easyfound(str_it, str.end()); |
|||
return (0); |
|||
} |
@ -0,0 +1,22 @@ |
|||
NAME = span |
|||
|
|||
SRCS = main.cpp Span.cpp |
|||
OBJS = $(SRCS:.cpp=.o) |
|||
|
|||
CXX = c++ |
|||
CXXFLAGS = -std=c++98 -Werror -Wextra -Wall |
|||
|
|||
$(NAME): $(OBJS) |
|||
$(CXX) -g $(CXXFLAGS) $(OBJS) -o $(NAME) |
|||
|
|||
all: $(NAME) |
|||
|
|||
clean: |
|||
rm -rf $(OBJS) |
|||
|
|||
fclean: clean |
|||
rm -rf $(NAME) |
|||
|
|||
re: fclean all |
|||
|
|||
.PHONY: all clean fclean re |
@ -0,0 +1,69 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Span.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/09/19 08:07:10 by narnaud #+# #+# */ |
|||
/* Updated: 2022/09/19 08:07:11 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Span.hpp" |
|||
|
|||
Span::Span(unsigned int N) : _capacity(N) {} |
|||
|
|||
Span::~Span() {} |
|||
|
|||
Span::Span(Span const &sp) { *this = sp; } |
|||
|
|||
Span &Span::operator=(Span const &sp) { |
|||
if (this == &sp) |
|||
return *this; |
|||
_vec = sp._vec; |
|||
_capacity = sp._capacity; |
|||
return (*this); |
|||
} |
|||
|
|||
void Span::addNumber(int const nb) { |
|||
if (_vec.size() == _capacity) |
|||
throw std::runtime_error("Too much number in span container."); |
|||
_vec.push_back(nb); |
|||
} |
|||
|
|||
unsigned int Span::shortestSpan() { |
|||
std::vector<int>::iterator it; |
|||
long ret; |
|||
|
|||
if (_vec.size() < 2) |
|||
throw std::runtime_error("Not enought number to get shortest span."); |
|||
sort(_vec.begin(), _vec.end()); |
|||
it = _vec.begin() + 1; |
|||
ret = *it - *(it - 1); |
|||
for (it = _vec.begin() + 2; it < _vec.end() && ret; it++) |
|||
if (*it - *(it - 1) < ret) |
|||
ret = *it - *(it - 1); |
|||
return (ret); |
|||
} |
|||
|
|||
unsigned int Span::longestSpan() { |
|||
if (_vec.size() < 2) |
|||
throw std::runtime_error("Not enought number to get shortest span."); |
|||
sort(_vec.begin(), _vec.end()); |
|||
return (*(_vec.end() - 1) - *_vec.begin()); |
|||
} |
|||
|
|||
void Span::addNRandom(unsigned int N) { |
|||
if (_vec.size() + N < _capacity) |
|||
throw std::runtime_error("Too much number to add into span container."); |
|||
srand((unsigned)time(NULL)); |
|||
for (unsigned int i = 0; i < N; i++) |
|||
_vec.push_back((rand() - INT_MAX / 2) * 2); |
|||
} |
|||
|
|||
void Span::addRange(std::vector<int>::iterator begin, std::vector<int>::iterator end) { |
|||
if (_vec.size() + end - begin > _capacity) |
|||
throw std::runtime_error("Container don't have enouth free space for range you want to add."); |
|||
std::copy(begin, end, std::back_inserter(_vec)); |
|||
} |
@ -0,0 +1,37 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Span.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/09/19 08:07:26 by narnaud #+# #+# */ |
|||
/* Updated: 2022/09/19 08:07:31 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include <exception> |
|||
#include <iostream> |
|||
#include <vector> |
|||
#include <algorithm> |
|||
#include <climits> |
|||
#include <time.h> |
|||
#include <numeric> |
|||
|
|||
class Span { |
|||
std::vector<int> _vec; |
|||
unsigned int _capacity; |
|||
public: |
|||
Span(); |
|||
Span(unsigned int N); |
|||
Span(Span const &sp); |
|||
~Span(); |
|||
Span &operator=(Span const &sp); |
|||
void addNumber(int nb); |
|||
unsigned int shortestSpan(); |
|||
unsigned int longestSpan(); |
|||
void addNRandom(unsigned int N); |
|||
void addRange(std::vector<int>::iterator begin, std::vector<int>::iterator end); |
|||
}; |
@ -0,0 +1,47 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/09/19 08:06:50 by narnaud #+# #+# */ |
|||
/* Updated: 2022/09/19 08:07:01 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Span.hpp" |
|||
#define RAND_SIZE 10000 |
|||
|
|||
int main(void) { |
|||
Span sp(10); |
|||
sp.addNumber(5); |
|||
sp.addNumber(4); |
|||
sp.addNumber(1); |
|||
sp.addNumber(-5); |
|||
|
|||
std::cout << "5 4 1 -1" << std::endl; |
|||
std::cout << "Shortest span: " << sp.shortestSpan() << std::endl; |
|||
std::cout << "Longest span: " << sp.longestSpan() << std::endl; |
|||
|
|||
Span sp2(RAND_SIZE); |
|||
sp2.addNRandom(RAND_SIZE); |
|||
|
|||
std::cout << RAND_SIZE << " numbers between " << INT_MIN << " and " << INT_MAX |
|||
<< std::endl; |
|||
std::cout << "Shortest span: " << sp2.shortestSpan() << std::endl; |
|||
std::cout << "Longest span: " << sp2.longestSpan() << std::endl; |
|||
|
|||
Span sp3(500); |
|||
std::vector<int> nums; |
|||
for (int n = 0; n < 500; n++) nums.push_back(n); |
|||
std::random_shuffle(nums.begin(), nums.end()); |
|||
sp3.addRange(nums.begin(), nums.begin() + 20); |
|||
std::cout << "Sp3:" << std::endl; |
|||
std::cout << "Shortest span: " << sp3.shortestSpan() << std::endl; |
|||
std::cout << "Longest span: " << sp3.longestSpan() << std::endl; |
|||
|
|||
sp3.addRange(nums.begin(), nums.end()); |
|||
|
|||
return (0); |
|||
} |
@ -0,0 +1,22 @@ |
|||
NAME = muted_stack |
|||
|
|||
SRCS = main.cpp |
|||
OBJS = $(SRCS:.cpp=.o) |
|||
|
|||
CXX = c++ |
|||
CXXFLAGS = -std=c++98 -Werror -Wextra -Wall |
|||
|
|||
$(NAME): $(OBJS) |
|||
$(CC) $(CXXFLAGS) $(OBJS) -o $(NAME) |
|||
|
|||
all: $(NAME) |
|||
|
|||
clean: |
|||
rm -rf $(OBJS) |
|||
|
|||
fclean: clean |
|||
rm -rf $(NAME) |
|||
|
|||
re: fclean all |
|||
|
|||
.PHONY: all clean fclean re |
@ -0,0 +1,30 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* MutantStack.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/09/19 09:39:40 by narnaud #+# #+# */ |
|||
/* Updated: 2022/09/19 09:39:45 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include <iostream> |
|||
#include <stack> |
|||
|
|||
template <class T> class MutantStack : public std::stack<T> { |
|||
public: |
|||
MutantStack<T>(void) {} |
|||
MutantStack<T>(const MutantStack<T> &st) { *this = st; } |
|||
~MutantStack<T>(void) {} |
|||
MutantStack<T> &operator=(const MutantStack<T> &st) { |
|||
(void)st; |
|||
return *this; |
|||
} |
|||
typedef typename std::stack<T>::container_type::iterator iterator; |
|||
iterator begin() { return this->c.begin(); } |
|||
iterator end() { return this->c.end(); } |
|||
}; |
@ -0,0 +1,37 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/09/19 09:39:50 by narnaud #+# #+# */ |
|||
/* Updated: 2022/09/19 09:40:01 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "MutantStack.hpp" |
|||
|
|||
int main() { |
|||
MutantStack<int> mstack; |
|||
mstack.push(5); |
|||
mstack.push(17); |
|||
std::cout << mstack.top() << std::endl; |
|||
mstack.pop(); |
|||
std::cout << mstack.size() << std::endl; |
|||
mstack.push(3); |
|||
mstack.push(5); |
|||
mstack.push(737); |
|||
//[...]
|
|||
mstack.push(0); |
|||
MutantStack<int>::iterator it = mstack.begin(); |
|||
MutantStack<int>::iterator ite = mstack.end(); |
|||
++it; |
|||
--it; |
|||
while (it != ite) { |
|||
std::cout << *it << std::endl; |
|||
++it; |
|||
} |
|||
std::stack<int> s(mstack); |
|||
return 0; |
|||
} |
Loading…
Reference in new issue