Just enumerate the function steps of the pseudo-algorithm and leave it to think later.
Description of function Required:
// get the same type of items and the smallest number
Specific function actions:
BOOL Bagmanager::obtain (item* pitem) { item// Get backpack similar item if ( Pitem) // presence of the item } else // The item does not exist directly add } returnfalse;
Very intuitive and easy to deal with, there is only need to modify the item parameters can be, there is no item added to the new lattice inside. But there might be a lattice, and then there are the remaining, we can actually let else's disposal, such as:
bool bagmanager::obtain (item* Pitem) { Item * Ptempitem = Finditembysourceid (Pitem->getsourceid ()); // get backpack similar items if (pitem) { // The item exists if (pitem->getnum S () > 0 ) { // direct add false ;}
However, there is also a problem, adding pitem the remaining quantity after a stack, or the number of itself pitem is far more than the maximum number of a lattice stack, you need to do more judgment on the remaining processing
BOOLBagmanager::obtain (item*pitem) {Item* Ptempitem = Finditembysourceid (Pitem->getsourceid ());//get backpacks for similar items if(pitem) {//the item exists } if(Pitem->getnums ()! =0&& pitem->getnums () > Pitem->getlimitstacknums ()) { //the number of remaining items is still greater than the maximum number of stacks in a grid } if(Pitem->getnums () >0) { //Remaining quantity Append } return false;}
The implementation of props stacking in the backpack