STL set doubts

Given:-

// Constructor of class Item
Item::Item(int s, Item_ *p)
{
item = new Item_();
item->id = s;
item->parent = p;
}

/*---------------------------------------------------------------------
Refer to the function given below, what does header.find returns and can the constructor be invoked just like that ?

head = header.find(Item(t->t[depth], 0));

---------------------------------------------------------------------*/

/*---------------------------------------------------------------------
what does the .first do ?

head = header.insert(Item(t->t[depth], 0)).first;

---------------------------------------------------------------------*/

int FPtree::processItems(Transaction *t, int times)
{
set::iterator head;
int added=0;

for(int depth=0; depth < t->length; depth++) {
head = header.find(Item(t->t[depth], 0));
if(head == header.end()) {
head = header.insert(Item(t->t[depth], 0)).first;
added++;
}
head->Increment(times);
}

return added;
}





Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories