Disclaimer: This is homework. I'm trying to do it and do not expect or anyone I have to do Just a few hints (heh) where I am wrong, it will be appreciated. For homework I need to create an When I insert 10,000 elements, it works fine, but if I get 100,000 elements, I get the following error: This is the code that I am running. I have commented it so it is easily readable. The error is probably because you have Besides, I can not understand why you are using Variable Sizes in Normal Ids in a Straight Array: int * array which holds 10 elements, and then attempting to insert one million ints into it. Checks if the array needs to be resized, and if it does, then I increase its size so that it is another element.
*** glibc detected ** *. / Set2: realloc (): invalid old size: 0x00000000024dc010 ***
start with zero main () {// 10 int curretsize = 10 size; Int * arr = malloc (augmented * sizeof (int)); Int i; // inconsistency with all elements set to INT_MAX (i = 0; i
arr in the function
Add , but this modified value is lost when
add returns. Then the next call to the
addition will be old, now the bad value will be received.
to search the loop to know you want to add to the last element, then why search Do you? Just allocate the array again and plug the new value into the new slot. Incidentally, I am pretty sure that your teacher is trying to see that re-allocation for each member causes unimpressive run time problems. Most of the
realloc will do a lot to copy with this algorithm. This is the reason that the actual program increases array size more than a factor rather than a certain amount (usually 1.5 or 2).
typedef struct array_s {int * elts; Integer shape; } VARIABLE_ARRAY; Zero Init (VARIABLE_ARRAY * A) {a-> Size = 10; A-> Altos = Mallow (A-> Size * Size A-> Altes [0]); // pomegranate returns for maloco (here)} records_image_image (VARIABLE_ARRAY * a, size_t size) {if (a-> size & lt; size) reset size due to the old size dimension / size here = 2 * A-> Shape; A-> Altts = reallock (size * size of A-> altts [0]); A-> Size = size; // Check for tap returns from realloc () HERE}} // Set the i'th position of the array. If there was not enough space, the extension of the array is so much there. Zero set (VARIABLE_ARRAY * a, int i, int val) {Ensure_ size (A, I + 1); A-> Alts [ii] = val } Zero test (zero) {VARIABLE_ARRAY a; Init (& a); For (Int i = 0; I <100000; i ++) {Set (and A, I, RAND ()); } ...}
Comments
Post a Comment