Hey Guys,
i am supposed to write an implementation of The PriorityQueue interface
in this user defined package, this is the first time im using iterator and so im having trouble.

at the moment im getting the following error message

PriorityQueueLinked.java:11: PriorityQueueLinked is not abstract and does not override abstract method iterator() in DAT.PriorityQueue
public class PriorityQueueLinked implements PriorityQueue  { 
       ^
1 error

Here's my code-sorry i havent written much documentation atm, this is just a quick draft

also im implementing this interface: http://undergraduate.csse.uwa.edu.au/units/CITS2200/Resources/DAT/DATDocumentation/

import DAT.PriorityQueue.*;
import DAT.*;
import Exceptions.*;
import java.lang.*;
import java.lang.Object.*;
import java.lang.Integer.*;

/** 
 * A Linked Priority Queue. 
 **/
public class PriorityQueueLinked implements PriorityQueue  { 
	private Link front;
	// Constructor 
	public PriorityQueueLinked() {
	front = null;
}


	/** 
	 * An inner class to hold the element, the successor, 
	 * and the priority 
	 **/
	public class Link { 
		Object element; 
		int priority; 
		Link next;
		public Link(Object e, int p, Link n) { 
			this.element = e; 
			this.priority = p; 
			this.next = n;
		}

	public boolean isEmpty() {
		return front == null;
	}
	
	public Object examine() throws Exception { 
		if (!isEmpty()) {
		return front.element; 
		} else throw new Exception("Empty Queue");
	}
	
	public Object dequeue() throws Exception { 
		if (!isEmpty()) {
			Object temp = front.element; 
			front = front.next; 
			return temp;
		} else throw new Exception("Empty Queue");
	}


	public void enqueue(Object e, int p) { 
		Iterator it = this.iterator();
		if (isEmpty() || p > front.priority) {
			front = new Link(e,p,front);
		} else {
			Link temp = (Link)it.next();
			while (it.hasNext() && temp.priority >= p) {
				it.next();
			}
				temp = new Link(e,p,temp);
		}
	}
		

	public class PriorityQueueIterator implements Iterator {
		private Link current;
						
		public PriorityQueueIterator()	{
			current = front;
		}
						
		public boolean hasNext () { 
			if(current.next != null)
				return true;
			return false;
		}
						
		public Link next () { 
			current = current.next;
			return current;
		}
						
		public void remove () { 
			throw new UnsupportedOperationException("Cannot remove from within queue.");
		}
	}	
					
		public Iterator iterator()	{
			return new PriorityQueueIterator();
		}
					
					
	}
}

Recommended Answers

All 2 Replies

What does mean the keyword implements PriorityQueue for PriorityQueueLinked class?

hey dw i figured it out, i put a bracket in the wrong place, everything works now :)
all my problems turn out to be something so trivial

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.