| /*␍␊ |
| * 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<Integer> _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;␍␊ |
| }␍␊ |
| ␍␊ |
| }␍␊ |