Anonymous user
Queue/Definition: Difference between revisions
m
→{{header|Java}}: Syntax highlighting, changed to queue method names
m (→{{header|Pascal}}: Free Pascal actually has a space in it ... Now the link works :-)) |
m (→{{header|Java}}: Syntax highlighting, changed to queue method names) |
||
Line 432:
=={{header|Java}}==
{{works with|Java|1.5+}}
This task could be done using a LinkedList from java.util, but here is a user-defined version with generics:▼
static class Node<E>{
▲This task could be done using a LinkedList from java.util, but here is a user-defined version:
▲ public class Queue<E>{
▲ Node<E> next;
▲ }
▲ }
▲ this.next= next;
▲ }
public void enqueue(E value){ //standard queue name for "push"
▲ public Queue(){
}▼
▲ if(empty()){
▲ }
▲ }else{
▲ tail.setNext(newNode);
}▼
▲ tail= newNode;
E retVal= head.value;
▲ public E pop() throws java.util.NoSuchElementException{
▲ if(empty()){
return retVal;
▲ throw new java.util.NoSuchElementException("No more elements.");
} ▼
▲ E retVal= head.value;
▲ head= head.getNext();
}</java>
▲ public boolean empty(){
▲ return head == null;
▲ }
=={{header|Pascal}}==
|