A container for a set of unique elements

I am trying to create a stack containing unique elements.

And if an element is pushed to what is already on the stack, the element is not pushed, but the existing element must be moved to the top of the stack, i.e. ABCD + B> ACDB

I would like here from you which container would be the best choice for this feature.

I decided to adapt the custom stack through the list because

  • the list provides a constant time for moving the List item
  • - This is one of the containers supported initially for the stack.

The drawback of my choice is that I have to manually check for duplicate elements.

PS My compiler is not so recent, so please do not offer unordered_set.

+5
source share
2 answers

+ + .

, , :

  • , ,
  • , , , , "" .

. , , , . ( , , < - messy phrase, !), .

+5

, , , , Max Heap.

(, ), , "" ( , ?).

  • : - (delete-max )
  • Push: , ""
    • "", (increase-key)
    • , (insert )

(20), vector .

+1

All Articles