Skip to content

Instantly share code, notes, and snippets.

@xynophon
Last active August 29, 2015 14:24
Show Gist options
  • Select an option

  • Save xynophon/fdf3d8a4c4dcfa850c90 to your computer and use it in GitHub Desktop.

Select an option

Save xynophon/fdf3d8a4c4dcfa850c90 to your computer and use it in GitHub Desktop.
CrackingCodingInterview. Implement Stack with LinkedList
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