diff -r 948d1bf1793110219055a2011186f92b7d1833f5 -r 7efa32a4dc11aeb6463ff1a1120f8a5f745ee5be java/stack/Main.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/stack/Main.java Wed Feb 20 23:29:56 2013 -0600 @@ -0,0 +1,19 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author nathan + */ +public class Main { + public static void main(String[] args) + { + Stack stk = new Stack(); + stk.push(5); + stk.push(10); + stk.push(1); + System.out.println(stk.max()); + } +} diff -r 948d1bf1793110219055a2011186f92b7d1833f5 -r 7efa32a4dc11aeb6463ff1a1120f8a5f745ee5be java/stack/Stack.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/stack/Stack.java Wed Feb 20 23:29:56 2013 -0600 @@ -0,0 +1,55 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author nathan + */ +public class Stack { + private List _container; + + public Stack() { + this._container = new ArrayList<>(); + } + public int pop() { + int ret = _container.get(0); + _container.remove(0); + return ret; + } + + public boolean push(int obj) { + try { + return _container.add(obj); + } catch (Exception e) { + throw e; + } + } + + public int peek() { + return _container.get(0); + } + + public boolean offer(int obj) { + try { + return _container.add(obj); + } catch (Exception e) { + return false; + } + } + + public int max() { + int max = _container.get(0); + for(int i = 1; i < _container.size(); i++) { + if (_container.get(i) > max) { + max = _container.get(i); + } + } + return max; + } + +}