This commit is contained in:
aortigos
2026-04-17 21:00:49 +02:00
commit ab04a0f8fa
3 changed files with 99 additions and 0 deletions

43
ex00/Makefile Normal file
View File

@@ -0,0 +1,43 @@
NAME = easyfind
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

29
ex00/easyfind.hpp Normal file
View File

@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* easyfind.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/04/17 20:26:54 by aortigos #+# #+# */
/* Updated: 2026/04/17 21:00:25 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
#include <vector>
template <typename T>
typename T::iterator easyfind(T array, int nb)
{
for(typename T::iterator it = array.begin();
it != array.end();
it++)
{
if (*it == nb)
{
return (it);
}
}
throw std::exception();
}

27
ex00/main.cpp Normal file
View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/04/17 20:26:58 by aortigos #+# #+# */
/* Updated: 2026/04/17 20:59:40 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "easyfind.hpp"
int main()
{
std::vector<int> arr;
arr.push_back(5);
arr.push_back(4);
arr.push_back(3);
arr.push_back(2);
std::cout << *easyfind(arr, 4) << std::endl;
return (0);
}