Author: Stan Eisenstat
Subject: Re: [Cs223] Dynamic Arrays
Date: Wednesday, 08 Apr 2020, 08:49:34
> Message Posted By: Unknown > > For the dynamic arrays, should we be using realloc() to allocate the > correct size of our arrays containing the triples each time we add a new > triple? If so, does realloc move automatically move char *'s and ints that > were created earlier, or do we have to manually do that? You may either use realloc(), which copies the previous contents if the address of the block changes; or use malloc(), copy the contents, and then free() the old block. ===== > Additionally, when keeping our arrays sorted, are we supposed be using a > sorting algorithm to sort all the elements of an array? If not, what other > tips do you have to keep the triples sorted? No, you should insert each new key in the correct location, which can be done in linear time. --Stan-PREV INDEX NEXT