mirror of
https://github.com/TheAlgorithms/C
synced 2025-02-12 11:34:58 +03:00
Update stack.c
This commit is contained in:
parent
5f138cc070
commit
8b6a93c8b3
@ -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];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user