G
Guest
Gast
hallo, also ich soll eine Doppelt verkettete, generische Liste MyList<Data> erstellen. Das Listenelement ist in ListElem.java vorgegeben.
ich hab eine nicht generische variante
wenn ich aber das in eine generische liste umwandeln will
krieg ich eine fehlermeldung, dass TypeData cannon be resolved...
danke im voraus
Code:
public class ListElem<TypeData extends Comparable<TypeData>>
{
/**
* Data element
*/
private TypeData value;
/**
* next element in list
*/
private ListElem<TypeData> next;
/**
* previous element in list
*/
private ListElem<TypeData> prev;
/**
* creates a new list element
* @param value is the data element of the new list element
* @param next is the next list element of the new list element
* @param previ is the previous element of the new list element
*/
public ListElem( TypeData value, ListElem<TypeData> next,
ListElem<TypeData> prev )
{
this.value = value;
this.next = next;
this.prev = prev;
}
/**
* replaces data of the element with given data s
* @param s is the new data
*/
public void setValue( TypeData s ){
this.value = s;
}
/**
* returns the data of the element
* @return data of the element
*/
public TypeData getValue(){
return this.value;
}
/**
* returns the next list element of the list element
* @return the next list element of the list element
*/
public ListElem<TypeData> getNext(){
return this.next;
}
/**
* replaces the next list element with the given list element
* @param next replaces the next list element
*/
public void setNext( ListElem<TypeData> next ){
this.next = next;
}
/**
* returns the previous list element of the list element
* @return the previous list element of the list element
*/
public ListElem<TypeData> getPrev(){
return this.prev;
}
/**
* replaces the previous list element with the given list element
* @param previous replaces the next list element
*/
public void setPrev( ListElem<TypeData> prev ){
this.prev = prev;
}
}
ich hab eine nicht generische variante
Code:
public class ListElem {
private Object value;
private ListElem next;
private ListElem prev;
public ListElem( Object value, ListElem next, ListElem prev ){
this.value = value;
this.next = next;
this.prev = prev;
}
public void setValue( Object s ){
this.value = s;
}
public Object getValue(){
return this.value;
}
public ListElem getNext(){
return this.next;
}
public void setNext( ListElem next ){
this.next = next;
}
public ListElem getPrev(){
return this.prev;
}
public void setPrev( ListElem prev ){
this.prev = prev;
}
}
Code:
public class List {
private ListElem first;
private ListElem last;
private int length;
/**
* Erzeugt eine leere Liste.
*/
public List() {
length = 0;
first = null;
last = null;
}
/**
* Gibt true zurueck, wenn die Liste keine Elemente enthaelt, false
* andernfalls.
*/
public boolean isEmpty() {
return (length == 0);
}
/**
* Entfernt alle Elemente aus der Liste.
*/
public void clear() {
first = null;
last = null;
length = 0;
}
/**
* Gibt die Laenge der Liste zurueck.
*/
public int getLength() {
return length;
}
wenn ich aber das in eine generische liste umwandeln will
Code:
public class MyList<Data> {
private ListElem<TypeData> first;
private ListElem<TypeData> last;
private int length;
/**
* Creates an empty list
*/
public MyList() {
length = 0;
first = null;
last = null;
}
public boolean isEmpty() {
return (length == 0);
}
/**
* Delete all elements from the list
*/
public void clear() {
first = null;
last = null;
length = 0;
}
krieg ich eine fehlermeldung, dass TypeData cannon be resolved...
danke im voraus