Hallo
als erstes das was ich benutzen darf..
So meine 1. aufgabe ist es alle gerade zahlen auszugeben mit system.print out
das was ich versucht habe
aber die zeile mit dem vergleich will iwie nicht klappen " current.getContent()%2==0" ... kann einer mir vllt weiter helfen...
Die zweite aufgabe ist es das maximum zu suchen und das zu löschen mit dem löschen weis ich ja wie das geht ..aber wie finde ich das maximum..
Mfg
als erstes das was ich benutzen darf..
Java:
public class DoublyLinkedList<T>
{
private Element<T> first, last;
private int size;
public DoublyLinkedList()
{
first = last = null;
size = 0;
}
public int size()
{
return size;
}
public boolean isEmpty()
{
return size == 0;
}
public void add( T content )
{
Element<T> e = new Element<T>( content );
if ( isEmpty() )
{
first = last = e;
}
else
{
last.connectAsNext( e );
last = e;
}
size++;
}
public void showAll()
{
Element<T> current = first;
while ( current != null )
{
if ( current.getContent() != null )
{
System.out.print( current.getContent().toString() );
if ( current != last )
{
System.out.print(", ");
}
}
current = current.getNext();
}
System.out.println();
}
public class Element<E>
{
private E content;
private Element<E> previous, next;
public Element( E c )
{
content = c;
previous = next = null;
}
public E getContent()
{
return content;
}
public void setContent( E c )
{
content = c;
}
public boolean hasNext()
{
return next != null;
}
public Element<E> getNext()
{
return next;
}
public void disconnectNext()
{
if ( hasNext() )
{
next.previous = null;
next = null;
}
}
public void connectAsNext( Element<E> e)
{
disconnectNext();
next = e;
if ( e != null )
{
e.disconnectPrevious();
e.previous = this;
}
}
public boolean hasPrevious()
{
return previous != null;
}
public Element<E> getPrevious()
{
return previous;
}
public void disconnectPrevious()
{
if ( hasPrevious() )
{
previous.next = null;
previous = null;
}
}
public void connectAsPrevious( Element<E> e )
{
disconnectPrevious();
previous = e;
if ( e != null )
{
e.disconnectNext();
e.next = this;
}
}
}
}
So meine 1. aufgabe ist es alle gerade zahlen auszugeben mit system.print out
das was ich versucht habe
Java:
public void showGerade()
{
Element<T> current = first;
while(current!=null)
{
if(current.getContent()!= null && current.getContent()%2==0)
{
System.out.print( current.getContent().toString());
if(current!=last)
{
System.out.print(", ");
}
}
current=current.getNext();
}
System.out.println();
}
Die zweite aufgabe ist es das maximum zu suchen und das zu löschen mit dem löschen weis ich ja wie das geht ..aber wie finde ich das maximum..
Mfg