mercredi 1 juin 2016

How do I decrease the count of an element in a multiset in C++?

For some reasons , I am using a multi-set in c++, which stores an element and the respective count of it when it is inserted.

Here , when i want to delete an element , I just want to decrease the count of that element in the set by 1 till it is >0.

FOr example

Code in c++

    multiset<int>mset;
    mset.insert(2);
    mset.insert(2);
    printf("%d ",mset.count(2)); //this returns 2
    // here i need an O(1) constant time function (in-built or whatever )
    // to decrease the count of 2 in the set without deleting it 
    // Remember constant time only

      -> Function and its specifications

    printf("%d ",mset.count(2)); // it should print 1 now .

Is there any way to achieve that or should i go by deleting that and inserting the element 2 by the required (count-1) times..?

Aucun commentaire:

Enregistrer un commentaire