I am trying to create a linked list which is sorted using the predifined methods for the interface but using my own code to rewrite the mehtods.
I have come across a problem and so far i have 1 error when compliling
the line it is pointing to is this
here is the whole code
I have come across a problem and so far i have 1 error when compliling
invalid method declaration; return type required
the line it is pointing to is this
Code:
public compare(E o1, E o2) {
here is the whole code
Code:
package linkedlist;
import java.util.*;
import java.util.SortedSet;
/**
*
* @author ag257
*/
public class LinkedList<E> extends AbstractCollection<E> implements SortedSet<E> {
private MyGenericContainer<E> header;
//private MyGenericContainer<E> bottom;
private int cargo;
private int numberContents;
private int size;
/** Creates a new instance of LinkedList */
public LinkedList() {
numberContents = 0;
size = 0;
}
public LinkedList (E contents) {
header = new MyGenericContainer<E> (contents);
//bottom = new MyGenericContainer<E> (contents);
numberContents = 1;
}
public void addNewContents (E contents) {
MyGenericContainer<E> next = new MyGenericContainer<E> (contents);
if (numberContents == 0) {
header = next;
}
else {
MyGenericContainer<E> current = header;
for (int i = 1; i < numberContents; i++ ) {
current = current.getNext();
}
current.setNext(next);
}
numberContents++;
}
public int size() {
return size;
}
public boolean isEmpty( ) {
return header.next == null;
}
public SortedSet subSet(E fromElement, E toElement) {
}
public SortedSet headSet(E toElement) {
}
public SortedSet tailSet(E fromElement) {
}
public E first() {
if (isEmpty()) {
throw new NoSuchElementException();
}
return header;
}
public E last() {
if (isEmpty()) {
throw new NoSuchElementException();
}
return header.next;
}
public Comparator<E> comparator() {
return new Comparator<E>() {
public compare(E o1, E o2) {
return o1.getContents().compareTo(o2.getContents());
}
public boolean equals(E obj) {
if(!(obj instanceof Comparator))
return false;
else
return true;
}
};
}
public Iterator<E> iterator() {
return new Iterator<E>() {
private MyGenericContainer<E> current = header;
E valueReturned;
private int counter = 0;
public boolean hasNext() {
if (counter >= numberContents){
return false;
}
else {
counter++;
return true;
}
}
public E next() {
valueReturned = current.getContents();
current = current.getNext();
return valueReturned;
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
}