Answer the question
In order to leave comments, you need to log in
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 T
list<T>
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question