public BTPosition<T> getSecondMax(BTPosition<T> root) {

		if (root == null)// empty tree
			return null;
		if (root.getLeft() == null && root.getRight() == null)// just one node
			return null;

		// more than two nodes
		BTPosition<T> current = root, lastNode = null;
		while (current.getRight() != null) {
			lastNode = current;
			current = current.getRight();
		}

		// check left subtree
		if (current.getLeft() != null) {
			current = current.getLeft();
			while (current.getRight() != null) {
				current = current.getRight();
			}
			return current;

		} else
			// return parent
			return lastNode;

	}