」 feat: ex02...

This commit is contained in:
y-syo
2025-08-27 06:13:06 +02:00
parent 98041eb662
commit 84819b741f
5 changed files with 136 additions and 0 deletions

View File

@@ -1,3 +1,5 @@
#pragma once
#include <algorithm> #include <algorithm>
template <typename T> template <typename T>

View File

@@ -1,3 +1,5 @@
#pragma once
#include <vector> #include <vector>
class Span { class Span {

58
ex02/Makefile Normal file
View File

@@ -0,0 +1,58 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/01/22 07:21:18 by mmoussou #+# #+# #
# Updated: 2025/08/27 02:35:51 by mmoussou ### ########.fr #
# #
# **************************************************************************** #
SHELL = bash
RED = \033[0;31m
GREEN = \033[0;32m
YELLOW = \033[1;33m
PURPLE = \e[0;35m
NC = \033[0m
DELETE = \x1B[2K
CC = c++
FLAGS = -std=c++98 -Wall -Werror -Wextra
INCLUDES = .
NAME = ex02
SRCS = main.cpp
OBJSDIR = obj/
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
all: $(NAME)
$(NAME): $(OBJS)
@$(CC) $(FLAGS) -I$(INCLUDES) $(OBJS) -o $(NAME)
@printf "$(NC)$(YELLOW)「✨」 feat($(NAME)): program compiled\n$(NC)"
$(OBJSDIR)%.o: %.cpp
@mkdir -p $(@D)
@$(CC) $(FLAGS) -I$(INCLUDES) -c $< -o $@
@printf "$(NC)$(GREEN)「🔨」 build($<): object compiled\n$(NC)"
clean:
@rm -f $(OBJS)
@printf "$(NC)$(RED)「🗑️」 clean($(OBJS)): object deleted\n$(NC)"
fclean: clean
@rm -f $(NAME)
@rm -Rf $(OBJSDIR)
@printf "$(NC)$(RED)「🗑️」 fclean($(NAME)): program deleted\n$(NC)"
re: fclean
@$(MAKE) -s all
.PHONY: clean fclean all re

46
ex02/MutantStack.hpp Normal file
View File

@@ -0,0 +1,46 @@
#pragma once
#include <stack>
#include <string>
#include <iostream>
template <typename T> class MutantStack : public std::stack<T> {
public:
MutantStack(void) {}
MutantStack(const MutantStack &cpy) : std::stack<T>(cpy) {}
~MutantStack(void) {}
MutantStack &operator=(const MutantStack &cpy)
{
if (this != &cpy)
{
std::stack<T>::operator=(cpy);
}
return *this;
}
typedef typename std::stack<T>::container_type::iterator iterator;
iterator begin(void)
{
return std::stack<T>::c.begin();
}
iterator end(void)
{
return std::stack<T>::c.end();
}
typedef typename std::stack<T>::container_type::const_iterator const_iterator;
const_iterator begin(void) const
{
return std::stack<T>::c.begin();
}
const_iterator end(void) const
{
return std::stack<T>::c.end();
}
private:
};

28
ex02/main.cpp Normal file
View File

@@ -0,0 +1,28 @@
#include "MutantStack.hpp"
#include <iostream>
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;
}