Any suggestion how to create dynamic array such as Stack(with pop, push, shift, and unshift) efficiently?Doing a realloc for every char in the string is REALLY bad coding practice.
Any suggestion how to create dynamic array such as Stack(with pop, push, shift, and unshift) efficiently?Doing a realloc for every char in the string is REALLY bad coding practice.
Use a predetermined size, then keep track of it. If allocation exceeds currently allocated buffer, then double the buffer using realloc and remember new size.
The idea to is to call realloc as little as possible, while still keeping the default size as low as possible (otherwise your program would be a memory hogger).