C
C
Clean Coder2019-03-26 13:53:32
C++ / C#
Clean Coder, 2019-03-26 13:53:32

How to remove duplicate elements from a list?

Suppose we are given a list of objects of the class . How to remove identical elements from it? (For example, turn the list {a, b, a, c, b} into {a, b, c}) class Tlist<T>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2019-03-26
@HustleCoder

In the general case, you sort, go through the list and remove adjacent identical elements.
But maybe it is necessary to solve the problem in a more radical way - instead of list, use a more suitable container - set? In set, the elements are already sorted and unique.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question