Hallo Leute,
Ich muss was für die Uni proggen, ne Hausaufgabenhilfe will ich nicht, aber ich habe ein Fehler
mit meinem Comparable. Ich sitze mehr als 2 Tage dran und hab schon Brute-Force mäßig alles ausprobiert. Es will nicht. In den Tutorials von Oracle finde ich auch nichts passendes dazu. Hier mal mein Code von allen Klassen die verwendet werden.
Das Interface darf ich nicht ändern!
Hier entsteht eigentlich auch der Fehler, den gebe ich nachdem Code
explizit nochmal an:
Hier der Fehler:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Bound mismatch: The type String is not a valid substitute for the bounded parameter <E extends Comparable<E>> of the type PQNode<E>
Bound mismatch: The type String is not a valid substitute for the bounded parameter <E extends Comparable<E>> of the type PQNode<E>
The method insert(PQNode<String>) in the type unsorted_linkedlist<PQNode<String>> is not applicable for the arguments (String)
The method insert(PQNode<String>) in the type unsorted_linkedlist<PQNode<String>> is not applicable for the arguments (String)
at Aufgabe_3.test.main(test.java:5)
Ich hoffe jemand kann mir da behilflich sein
Ich muss was für die Uni proggen, ne Hausaufgabenhilfe will ich nicht, aber ich habe ein Fehler
mit meinem Comparable. Ich sitze mehr als 2 Tage dran und hab schon Brute-Force mäßig alles ausprobiert. Es will nicht. In den Tutorials von Oracle finde ich auch nichts passendes dazu. Hier mal mein Code von allen Klassen die verwendet werden.
Das Interface darf ich nicht ändern!
Java:
public interface PriorityQueue<E extends Comparable<E>> {
E findMin() throws PREmptyException;
E deleteMin() throws PREmptyException;
void insert(E element) throws PQFullException;
boolean isEmpty();
int size();
}
Java:
public class PQNode<E extends Comparable<E>> implements Comparable<E> {
private E value;
PQNode<E> prev,next;
public PQNode(E value, PQNode<E> prev, PQNode<E> next){
this.value = value;
this.prev = prev;
this.next = next;
}
public E getValue(){
return value;
}
// public int compareTo(PQNode<E> o) {
// return getValue().compareTo(o.getValue());
// }
public PQNode<E> getPrev(){
return prev;
}
public PQNode<E> getNext(){
return next;
}
public void setNext(PQNode<E> next){
this.next = next;
}
public void setPrev(PQNode<E> prev){
this.prev = prev;
}
@Override
public int compareTo(E o) {
return getValue().compareTo(o);
}
}
Java:
public class unsorted_linkedlist<E extends Comparable<E>> implements PriorityQueue<E> {
PQNode<E> tail,head,current;
static int counter = 0;
@SuppressWarnings({ "unchecked", "rawtypes" })
public unsorted_linkedlist(){
head = new PQNode(null,null,tail);
tail = new PQNode(null,head,null);
current = head;
}
public E findMin() throws PREmptyException {
PQNode<E> temp = null;
if(head.getNext() != null){ current = head.getNext(); temp = head.getNext(); }
while(temp.getNext() != null)
{
temp = temp.getNext();
if(current.compareTo(temp.getValue()) < 0)
current = temp;
}
return current.getValue();
}
public E deleteMin() throws PREmptyException {
E returnTemp = findMin();
PQNode<E> temp = current;
current.getPrev().setNext(current.getNext());
current.getNext().setPrev(temp.getPrev());
return returnTemp;
}
public void insert(E element) throws PQFullException {
PQNode<E> temp = new PQNode<E>(element,tail.getPrev(),tail);
tail.getPrev().setNext(temp);
tail.setPrev(temp);
counter++;
}
public boolean isEmpty() {
return (counter == 0);
}
public int size() {
return counter;
}
Hier entsteht eigentlich auch der Fehler, den gebe ich nachdem Code
explizit nochmal an:
Java:
public class test {
public static void main(String[] args) {
unsorted_linkedlist<String> test = new unsorted_linkedlist<String>();
test.insert("Hallo");
test.insert("Element");
System.out.println(test.deleteMin());
}
}
Hier der Fehler:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Bound mismatch: The type String is not a valid substitute for the bounded parameter <E extends Comparable<E>> of the type PQNode<E>
Bound mismatch: The type String is not a valid substitute for the bounded parameter <E extends Comparable<E>> of the type PQNode<E>
The method insert(PQNode<String>) in the type unsorted_linkedlist<PQNode<String>> is not applicable for the arguments (String)
The method insert(PQNode<String>) in the type unsorted_linkedlist<PQNode<String>> is not applicable for the arguments (String)
at Aufgabe_3.test.main(test.java:5)
Ich hoffe jemand kann mir da behilflich sein