Skip to content

Instantly share code, notes, and snippets.

@mchayapol
Created September 30, 2015 02:51
Show Gist options
  • Save mchayapol/5a04a5a076f82aae3b97 to your computer and use it in GitHub Desktop.
Save mchayapol/5a04a5a076f82aae3b97 to your computer and use it in GitHub Desktop.
Queue Skeleton
package edu.au.scitech.sc2101;
import edu.au.scitech.sc2101.IntegerLinkedList.Node;
public class Queue extends IntegerLinkedList {
Node tail;
@Override
public void add(int newValue) {
// add to the end of the list
// utilise tail pointer
Node n = new Node(newValue);
if (head == null) {
// new list, just update head
head = n;
tail = head;
} else {
tail.next = n;
tail = n;
}
}
public void enqueue(int value) {
add(value);
}
public int dequeue() {
int value = getNode(0).value;
delete(0);
return value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment