add item, ensures that the data structure can hold the item NOTE: realloc() possibly called return 0 on success; -1 on failure
| 194 | // NOTE: realloc() possibly called |
| 195 | // return 0 on success; -1 on failure |
| 196 | int Heap_offer |
| 197 | ( |
| 198 | heap_t **hp, // pointer to the heap, changed when heap is enlarged |
| 199 | void *item // item The item to be added |
| 200 | ) { |
| 201 | if(NULL == (*hp = __ensurecapacity(*hp))) { |
| 202 | return -1; |
| 203 | } |
| 204 | |
| 205 | __Heap_offerx(*hp, item); |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | // add item |
| 210 | // an error will occur if there isn't enough space for this item |