Skip to content

Instantly share code, notes, and snippets.

@hawkw
Created April 3, 2013 14:15
Show Gist options
  • Save hawkw/5301585 to your computer and use it in GitHub Desktop.
Save hawkw/5301585 to your computer and use it in GitHub Desktop.
what's wrong with this picture?
public E peek () throws EmptyStackException {
if (empty())
throw new EmptyStackException();
return stack[top];
}
public E pop () throws EmptyStackException {
if (empty())
throw new EmptyStackException();
E element = stack[top];
stack[top--] = null;
return element;
}
public boolean empty () {
try {
peek();
} catch (EmptyStackException e) {
return true;
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment