Unofficial C Solution to Problem 3.1 in Cracking the Coding Interview (5th Edition)

19 Jul

I used a different solution from the ones in the original book. In the first official solution in the book, one stack might be full while another is empty. The space utilization is bad. In the second official solution, once one stack is full while some other one is not, we need to shift the stack by moving every element in it. When this happens, it is time-consuming. While in our solution, using list in array, we could use all of these three stacks until globally no space is available. And all the three major operations (pop, peek, and push) is O(1). The disadvantage of our solution is that, we need some additional space to store the list information. So we cannot use all the allocated space to just store the stack data.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please put your code into a <pre>YOUR CODE</pre> section. Thanks and Happy Coding!