Java Reference
In-Depth Information
/
**
Setcurratlistend
*
/
publicvoidmoveToEnd()
{curr=tail;}
/
**
Movecurronestepleft;nochangeifnowatfront
*
/
publicvoidprev(){
if(curr==head)return;//Nopreviouselement
Link<E>temp=head;
//Marchdownlistuntilwefindthepreviouselement
while(temp.next()!=curr)temp=temp.next();
curr=temp;
}
/
**
Movecurronestepright;nochangeifnowatend
*
/
publicvoidnext()
{if(curr!=tail)curr=curr.next();}
/
**
@returnListlength
*
/
publicintlength(){returncnt;}
/
**
@returnThepositionofthecurrentelement
*
/
publicintcurrPos(){
Link<E>temp=head;
inti;
for(i=0;curr!=temp;i++)
temp=temp.next();
returni;
}
/
**
Movedownlistto"pos"position
*
/
publicvoidmoveToPos(intpos){
assert(pos>=0)&&(pos<=cnt):"Positionoutofrange";
curr=head;
for(inti=0;i<pos;i++)curr=curr.next();
}
/
**
@returnCurrentelementvalue
*
/
publicEgetValue(){
if(curr.next()==null)returnnull;
returncurr.next().element();
}
Figure4.8
(continued)