Ordered Data Structure that allows to efficiently remove duplicate items

Posted by devoured elysium on Stack Overflow See other posts from Stack Overflow or by devoured elysium
Published on 2010-05-31T17:18:04Z Indexed on 2010/05/31 17:23 UTC
Read the original article Hit count: 133

Filed under:
|
|

I need a data structure that

  • Must be ordered (adding elements a, b and c to an empty structure, will make them be at positions 0, 1 and 2).
  • Allows to add repeated items. This is, I can have a list with a, b, c, a, b.
  • Allows removing all ocurrences of a given item (if I do something like delete(1), it will delete all ocurrences of 1 in the structure).

I can't really pick what the best data structure could be in here. I thought at first about something like a List(the problem is having an O(n) operation when removing items), but maybe I'm missing something? What about trees/heaps? Hashtables/maps?

I'll have to assume I'll do as much adding as removing with this data structure.

Thanks

© Stack Overflow or respective owner

Related posts about c#

Related posts about java