Created
September 30, 2015 02:51
-
-
Save mchayapol/5a04a5a076f82aae3b97 to your computer and use it in GitHub Desktop.
Queue Skeleton
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
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