Samsa
Commander
- Registriert
- Dez. 2005
- Beiträge
- 2.614
Hi,
ich habe von meiner Freundin einen Javaquelltext gekriegt. Sie hat mich gebeten diesen durchzukommentieren. Da ich von Java aber null Ahnung habe wollte ich fragen ob sich hier jemand bereiterklären würde dies zu machen. Es handelt sich um eine einfache verkettete Liste.
(Es ist auch nicht viel Code.
)
Gruß, Jan
ich habe von meiner Freundin einen Javaquelltext gekriegt. Sie hat mich gebeten diesen durchzukommentieren. Da ich von Java aber null Ahnung habe wollte ich fragen ob sich hier jemand bereiterklären würde dies zu machen. Es handelt sich um eine einfache verkettete Liste.
(Es ist auch nicht viel Code.
Gruß, Jan
Code:
Klasse List:
package packList;
public class List
{
ListNode first;
ListNode last;
ListNode pos;
public List()
{ first = null;
last= null;
pos= null;
}
public boolean isEmpty()
{ return first == null;
}
public void add(ListNode n) // Debug!
{ if (isEmpty() )
{ first=n;
last=n;
pos=n;
}
else
{ last.next =n;
last=n;
}
}
public void toFirst()
{ if (!(isEmpty()))
{ pos=first;
}
}
public void toLast()
{ if (! (isEmpty()))
{ pos=last;
}
}
public void next()
{ if (!(isEmpty()) & !isBehind())
{ pos= pos.next;
}
}
public void previous()
{ if (! (isEmpty())& !isBefore())
{ pos=getPrevious();
}
}
public boolean isBefore()
{ return pos==first;
}
public boolean isBehind()
{return pos==last;
}
public int getItem()
{ if(! (isEmpty()))
{ return pos.data;
}
return 0;
}
public void update (ListNode n)
{ if (! (isEmpty()))
{ pos.data=n.data;
}
}
private ListNode getPrevious()
{ ListNode seek=first;
if (! (isEmpty()))
{
while(!(seek.next==pos))
{ //Suchen....\m/seek=seek.next;
}
return seek;
}
return null;
}
public void insertBehind(ListNode n)
{ if (isEmpty())
{ first=n;
last=n;
pos=n;
}
else
{ n.next=pos.next;
pos.next=n;
if(pos==last) last=n;
}
}
public void insertBefore(ListNode n)
{ if (isEmpty())
{ first=n;
last=n;
pos=n;
}
else if(pos==first)
{ n.next=first;
first=n;
}
else
{ n.next=getPrevious().next;
getPrevious().next=n;
}
}
public void delete()
{
if(!(isEmpty()))
{
if(isBehind() && isBefore())
{ first=null;
last=null;
pos=null;
}
else if(isBehind())
{ last=getPrevious();
getPrevious().next=null;
pos=last;
}
else if (isBefore())
{ first=pos.next;
pos=first;
}
else
{ getPrevious().next=pos.next;
pos=pos.next;
}
}
}
}