Skip to content

Instantly share code, notes, and snippets.

@jonghwanhyeon
Created December 25, 2013 07:53
Show Gist options
  • Save jonghwanhyeon/8121165 to your computer and use it in GitHub Desktop.
Save jonghwanhyeon/8121165 to your computer and use it in GitHub Desktop.
class List {
public Item removeFirst() throws ListException {
if (this.count() <= 0) throw new ListException("no more item");
Item item = /* remove the first item from the list */;
return item;
}
}
class Stack {
private List list;
public item pop1() throws StackException{
if (list.count() <= 0) throw new StackException("no more item");
try {
return list.removeFirst();
} catch (ListException exception) { }
return null; // rarely reachable
}
public item pop2() throws ListException {
return list.removeFirst();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment