Update stack.c

This commit is contained in:
megahertz66 2019-07-12 13:16:51 +08:00 committed by GitHub
parent 5f138cc070
commit 8b6a93c8b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,7 +42,7 @@ void initStack()
grow: increases the stack by 10 elements.
This utility function isn't part of the public interface
*/
void grow(void ** oldMemory)
void grow()
{
max += 10; /* increases the capacity */
@ -52,10 +52,10 @@ void grow(void ** oldMemory)
/* copies the elements from the origin array in the new one. */
for (i = 0; i < max - 10; i++)
{
*(tmp + i) = *(oldMemory + i);
*(tmp + i) = *(array + i);
}
/*free the memory */
free(oldMemory);
free(array);
array = tmp;
}
@ -82,7 +82,7 @@ void push(void *object)
else /* stack is full */
{
grow(array); /* lets grow stack */
grow(); /* lets grow stack */
push(object); /* recursive call */
}
}
@ -134,4 +134,4 @@ void *top()
{
/* offset address points to the top element */
return array[offset];
}
}