Skip to content

Instantly share code, notes, and snippets.

@kanrourou
Created January 10, 2014 22:59
Show Gist options
  • Save kanrourou/8364351 to your computer and use it in GitHub Desktop.
Save kanrourou/8364351 to your computer and use it in GitHub Desktop.
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