We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e5dad3f commit fc37289Copy full SHA for fc37289
data_structures/stack/stack.c
@@ -45,17 +45,8 @@ void grow()
45
{
46
max += 10; /* increases the capacity */
47
48
- int i; // for the loop
49
- void **tmp = malloc(sizeof(void *) * max);
50
-
51
- /* copies the elements from the origin array in the new one. */
52
- for (i = 0; i < max - 10; i++)
53
- {
54
- *(tmp + i) = *(array + i);
55
- }
56
- /*free the memory */
57
- free(array);
58
- array = tmp;
+ array = (void **)realloc(array, sizeof(void *) * max);
+ assert(array); /* tests whether pointer is assigned to memory. */
59
}
60
61
/* push: pushs the argument onto the stack */
0 commit comments