I'm having great difficulty coming up with an enqueue method for my queue class. I need it so that the head will toString() into with it pointing to A first. And the tail to be pointing at C where insertion into the queue will happen. I just need a push in the right direction, thanks!
public class SinglyLinkedQueue {
public static void main(String[] args) {
SinglyLinkedQueue myQueue = new SinglyLinkedQueue();
myQueue.enqueue("A");
myQueue.enqueue("B");
myQueue.enqueue("C");
System.out.println(myQueue.toString());
}
private SinglyLinkedNode head = new SinglyLinkedNode("",null);
private SinglyLinkedNode tail = new SinglyLinkedNode("",null);
public boolean isEmpty() {
return head == null && tail == null;
}
public String toString() {
if(isEmpty() == true) {
return "";
} else {
return toString(head);
}
}
public String toString(SinglyLinkedNode n1) {
if(n1 == null) {
return "";
}
String comma = "<";
if(head != n1) {
comma = ",";
} if(n1.getNext() == null) {
comma = ">";
}
return comma+n1.getValue()+toString(n1.getNext());
}
public void enqueue(String str) {
}
}