Queue implementations

Run Settings
LanguageJava
Language Version
Run Command
class Main { public static void main(String[] args) { LinkedQueueOfStrings q = new LinkedQueueOfStrings(); for (int i = 0; i < 100; i++) { q.enqueue(String.valueOf(i)); } for (int i = 0; i < 100; i++) { System.out.println(q.dequeue()); } } } class LinkedQueueOfStrings { private Node first, last; private class Node { String item; Node next; } public boolean isEmpty() { return first == null; } public void enqueue(String item) { Node oldlast = last; last = new Node(); last.item = item; last.next = null; if (isEmpty()) first = last; else oldlast.next = last; } public String dequeue() { String item = first.item; first = first.next; if (isEmpty()) last = null; return item; } }
Editor Settings
Theme
Key bindings
Full width
Lines