Last active
January 2, 2016 21:38
-
-
Save kanrourou/8364323 to your computer and use it in GitHub Desktop.
This file contains 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
public class LinkedListStackOfStrings{ | |
private class Node{ | |
private String item; | |
private Node next; | |
} | |
private Node first=null; | |
public boolean isEmpty(){ | |
if(first==null) | |
return true; | |
else | |
return false; | |
} | |
public void push(String s){ | |
Node oldfirst=first; | |
first=new Node(); | |
first.item=s; | |
first.next=oldfirst; | |
} | |
public String pop(){ | |
if(!isEmpty()){ | |
String s=first.item; | |
first=first.next; | |
return s; | |
} | |
else | |
return "Stack is empty!"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment