aboutsummaryrefslogtreecommitdiff
path: root/libft/src/algo/ft_reverse.c
blob: c6173388979b14023b9cfef9cdeb4815ea74c35c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_reverse.c                                       :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/10 05:07:13 by cacharle          #+#    #+#             */
/*   Updated: 2020/04/04 22:36:23 by charles          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "libft_algo.h"

/*
** \brief        Reverse an array
** \param base   Array to reverse
** \param nel    Number of element in the array
** \param width  Size of each elements
*/

void	ft_reverse(void *base, size_t nel, size_t width)
{
	size_t	i;

	i = 0;
	nel--;
	while (i < nel)
	{
		ft_memswap(base + i * width, base + nel * width, width);
		i++;
		nel--;
	}
}