imaginary IV question: BAG data structure

A “Bag” data structure is a generalized Set that allows duplicates. Implement it in your choice of language. Let’s take python for example:

myBag = Bag()
myBag.add(‘x’)
myBag.add(‘x’)
myBag.add(‘y’)
myBag.size() == 3
myBag.count(‘x’) == 2
myBag.remove1(‘x’)
myBag.count(‘x’) == 1

I think a unordered_multiset is similar.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s