Created
December 25, 2013 07:53
-
-
Save jonghwanhyeon/8121165 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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