public T peek() { if (topNode != null) { return topNode.getValue(); } return null; }
void printStack() { StackNode current; current = start; while (current != null) { System.out.println("->" + current.getValue()); current = current.getNext(); } }
public T findMax() { StackNode<T> currentNode = topNode; T max = topNode.getValue(); while (currentNode != null) { T currentValue = currentNode.getValue(); if (currentValue > max) { max = currentValue; } currentNode = currentNode.getLastNode(); } return max; }
public void print() { StackNode<T> currentNode = topNode; while (currentNode != null) { System.out.println(currentNode.getValue()); currentNode = currentNode.getLastNode(); } }
public T pop() { if (topNode != null) { StackNode newTopNode = topNode.getLastNode(); T topNodeValue = topNode.getValue(); newTopNode.setNextNode(null); topNode.setLastNode(null); topNode = newTopNode; return topNodeValue; } return null; }
public T findMin(T currentMin, T max) { StackNode<T> currentNode = topNode; T min = max; while (currentNode != null) { T currentValue = currentNode.getValue(); if (currentMin == null) { if (currentValue < min) { min = currentValue; } } else { if (currentValue < min && currentValue > currentMin) { min = currentValue; } } currentNode = currentNode.getLastNode(); } return min; }
char peep() { return start.getValue(); }