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

31 Jul

In my solution, I used a structure with two traditional stacks. One of them is used to store the original elements. The other is used to store the latest minimum elements. At any time, the top element in the second stack is the minimum value among all the available contents in the first stack.

By the way, the function “stack_shell” is kind of bad. Too many nested IF-ELSE statement makes it hard to code furthermore and debug. A better solution might utilize the style of function “shell_usage” and some small functions.

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!