Remove duplicates from a list of positive integers
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in), | dimension(:) | :: | l | List for de-duplication |
List without duplicates
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module.
function deDup(l) result(o)
!! Remove duplicates from a list of positive integers
integer,dimension(:),intent(in)::l
!! List for de-duplication
integer,dimension(:),allocatable::o
!! List without duplicates
integer,dimension(:),allocatable::b
integer::T,k
b = l
do k=1,size(b)
T = b(k)
where(b==T) b = -1
b(k) = T
end do
o = pack(b,b>0)
end function deDup