Created
January 10, 2014 22:59
-
-
Save kanrourou/8364351 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
public class LinkedListQueueOfStrings{ | |
public class Node{ | |
private String item; | |
private Node next; | |
} | |
private Node first=null; | |
private Node last=null; | |
public boolean isEmpty(){ | |
return first==null; | |
} | |
public void enqueue(String s){ | |
Node oldlast=last; | |
last=new Node(); | |
last.item=s; | |
last.next=null; | |
if(isEmpty()) | |
first=last; | |
else | |
oldlast.next=last; | |
} | |
public String dequeue(){ | |
if(!isEmpty()){ | |
String s=first.item; | |
first=first.next; | |
return s; | |
} | |
else{ | |
last=null; | |
return "Queue is empty!"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment