Wednesday, November 11, 2009

Stack implementation - NPTEL -Lecture 2(Stacks)

Below is the implementation of a simple stack based on the Stacks Lecture. A straight forward implementation in Java which supports both the growth strategy and the tight strategy for increasing the stack size.


Stack - Interface with Stack methods
MyStack - Concrete implementation
StackOverFlowException - Thrown when we run out of memory
StackEmptyException Thrown when the user calls top or pop when Stack is empty
StockSpanAlgorithm This class implements the calculating stock span (javadoc describes what the problem is) using both a trivial implementation (O(n**2)) and using Stacks (O(n))
Utils - Utils class which prints the array contents to the output

I am thinking instead of using pastie to post my code, I am better off using github.Lets see how that goes

No comments: