Last active
August 29, 2015 14:24
-
-
Save xynophon/fdf3d8a4c4dcfa850c90 to your computer and use it in GitHub Desktop.
CrackingCodingInterview. Implement Stack with LinkedList
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 StackList { | |
| Node top; | |
| void push(Object data){ | |
| Node t = new Node(data); | |
| t.next = top; | |
| top = t; | |
| } | |
| Object pop(){ | |
| if(top == null){ | |
| return null; | |
| }else{ | |
| Object item = top.data; | |
| top = top.next; | |
| return item; | |
| } | |
| } | |
| Object peek(){ | |
| if(top == null){ | |
| return null; | |
| } | |
| return top.data; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment