int main() { ArrayType arr; initArray(&arr,2); arr.array[0] = 1; arr.array[1] = 2; printArray(&arr); if(isArrayFull(&arr,3)) { extendArray(&arr,4); arr.array[2] = 3; arr.array[3] = 4; } printArray(&arr); freeArray(arr); return 0; }
/*! * add() * * Input: lheap * item to be added to the tail of the heap * Return: 0 if OK, 1 on error */ int MinHeap::add(struct HeapEle *item) { if (!item) return 1; /* If necessary, expand the allocated array by a factor of 2 */ if (this->n >= this->nalloc) extendArray(); /* Add the item */ item->id = this->n; this->ptrArray[this->n] = item; this->n++; /* Restore the heap */ return swapUp(this->n - 1); }
int main(int argc,char **argv){ extendArray(1,6); printf("server done\n"); return 0; }