Data Structures and Other Objects Using Java
Data Structures and Other Objects Using Java
October 2, 2011 - 14:27
i got a error message it telling: manynodes doesnt equal node plz hekp
* Add a new element to this sequence, before the current element.
* @param element
* the new element that is being added
* @postcondition
* The element has been added to this sequence. If there was
* a current element, then the new element is placed before the current
* element. If there was no current element, then the new element is placed
* at the start of the sequence. In all cases, the new element becomes the
* new current element of this sequence.
* @exception OutOfMemoryError
**/
public void addBefore(HexTile element)
{
assert _wellFormed() : "invariant wrong at start of addBefore";
// TODO: Implemented by student.
// several cases:
// (1) sequence is empty
// (2) inserting at head
// (3) inserting elsewhere
if(_head == null){
_head=_cursor=_tail=new Node(element, null);
//
}else if(_cursor == null){ the problem is her
//_cursor=new Node(element,_cursor);
//_cursor= _head.next;
if(_cursor == _head){
_head=_cursor=new Node(element,_precursor);
}else{
_head=_cursor=new Node(element,null);
}
}else{
_cursor= new Node(element, _cursor);
_precursor.next=_cursor;
}
_manyNodes++;
assert _wellFormed() : "invariant wrong at end of addBefore";
}




