ex02
This commit is contained in:
43
ex02/Makefile
Normal file
43
ex02/Makefile
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
NAME = mutanstack
|
||||||
|
|
||||||
|
SRC = main.cpp
|
||||||
|
|
||||||
|
|
||||||
|
OBJ = $(SRC:.cpp=.o)
|
||||||
|
|
||||||
|
CC = c++
|
||||||
|
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||||
|
|
||||||
|
GREEN = \033[0;32m
|
||||||
|
RED = \033[0;31m
|
||||||
|
RESET = \033[0m
|
||||||
|
|
||||||
|
TOTAL := $(words $(SRC))
|
||||||
|
COUNT = 0
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(OBJ)
|
||||||
|
@rm -f .build_start
|
||||||
|
@$(CC) $(CFLAGS) $(OBJ) -o $(NAME)
|
||||||
|
@printf "\n$(GREEN)✔ Listo (100%%)\n$(RESET)"
|
||||||
|
|
||||||
|
%.o: %.cpp
|
||||||
|
@if [ ! -f .build_start ]; then printf "$(GREEN)Compilando archivos...\n$(RESET)"; touch .build_start; fi
|
||||||
|
@$(eval COUNT = $(shell echo $$(($(COUNT)+1))))
|
||||||
|
@PERCENT=$$(($(COUNT)*100/$(TOTAL))); \
|
||||||
|
BAR=$$(printf "%0.s#" $$(seq 1 $$((PERCENT/5)))); \
|
||||||
|
SPACE=$$(printf "%0.s " $$(seq 1 $$((20-PERCENT/5)))); \
|
||||||
|
printf "\r [$$BAR$$SPACE] %3d%% (%d/%d) $< " $$PERCENT $(COUNT) $(TOTAL)
|
||||||
|
@$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@printf "$(RED)Eliminando...\n$(RESET)"
|
||||||
|
@rm -f $(OBJ)
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
@rm -f $(NAME)
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
|
|
||||||
|
.PHONY: all clean fclean re
|
||||||
43
ex02/MutantStack/MutantStack.hpp
Normal file
43
ex02/MutantStack/MutantStack.hpp
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* MutantStack.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: aortigos <aortigos@student.42malaga.com> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/04/21 11:32:08 by aortigos #+# #+# */
|
||||||
|
/* Updated: 2026/04/21 11:32:08 by aortigos ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef MUTANTSTACK_HPP
|
||||||
|
# define MUTANTSTACK_HPP
|
||||||
|
|
||||||
|
# include <iostream>
|
||||||
|
# include <stack>
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class MutantStack : public std::stack<T>
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
public:
|
||||||
|
MutantStack();
|
||||||
|
MutantStack(const MutantStack &other);
|
||||||
|
MutantStack& operator=(const MutantStack &other);
|
||||||
|
~MutantStack();
|
||||||
|
|
||||||
|
typedef typename std::stack<T>::container_type::iterator iterator;
|
||||||
|
typedef typename std::stack<T>::container_type::const_iterator const_iterator;
|
||||||
|
|
||||||
|
iterator begin();
|
||||||
|
iterator end();
|
||||||
|
|
||||||
|
const_iterator begin() const;
|
||||||
|
const_iterator end() const;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#include "MutantStack.tpp"
|
||||||
|
|
||||||
|
#endif
|
||||||
63
ex02/MutantStack/MutantStack.tpp
Normal file
63
ex02/MutantStack/MutantStack.tpp
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* MutantStack.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: aortigos <aortigos@student.42malaga.com> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/04/21 11:32:08 by aortigos #+# #+# */
|
||||||
|
/* Updated: 2026/04/21 11:32:08 by aortigos ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
MutantStack<T>::MutantStack() : std::stack<T>()
|
||||||
|
{
|
||||||
|
// std::cout << "Span default constructor called" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
MutantStack<T>::MutantStack(const MutantStack &other)
|
||||||
|
{
|
||||||
|
*this = other;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
MutantStack<T>& MutantStack<T>::operator=(const MutantStack &other)
|
||||||
|
{
|
||||||
|
if (this != &other)
|
||||||
|
{
|
||||||
|
std::stack<T>::operator=(other);
|
||||||
|
}
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
MutantStack<T>::~MutantStack()
|
||||||
|
{
|
||||||
|
// std::cout << "MutantStack destructor called" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename MutantStack<T>::iterator MutantStack<T>::begin()
|
||||||
|
{
|
||||||
|
return (this->c.begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename MutantStack<T>::iterator MutantStack<T>::end()
|
||||||
|
{
|
||||||
|
return (this->c.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename MutantStack<T>::const_iterator MutantStack<T>::begin() const
|
||||||
|
{
|
||||||
|
return (this->c.begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename MutantStack<T>::const_iterator MutantStack<T>::end() const
|
||||||
|
{
|
||||||
|
return (this->c.end());
|
||||||
|
}
|
||||||
40
ex02/main.cpp
Normal file
40
ex02/main.cpp
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/04/21 11:31:38 by aortigos #+# #+# */
|
||||||
|
/* Updated: 2026/04/21 12:00:20 by aortigos ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "MutantStack/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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user