

        // make sure we have something to remove
        if (size == 0)
            System.err.println("Error:  Attempt to remove fron an empty list");

        // starting at the beginning check for removal
        currentNode = getFirst ();
        if (currentNode == nodeToRemove)
            removeFirst ();
        currentNode = getLast ();
        if (currentNode == nodeToRemove)
            removeLast ();

        // we've already check two nodes, check the rest
        if (size - 2 > 0) {
            nodeBefore = getFirst ();
            currentNode = getFirst ().getNext ();
            for (int count = 0; count < size - 2; count++) {
                if (currentNode == nodeToRemove) {
                    // remove current node
                    nodeBefore.setNext (currentNode.getNext ());
                    size--;
                    break;
                }  // end if node found

                // change references
                nodeBefore = currentNode;
                currentNode = currentNode.getNext ();
            }  // end loop to process elements
        }  // end if size - 2 > 0

    }  // end method remove

    // the gets to return the head and/or tail nodes and size of the list
    public Node<V> getFirst () { return head; }
    public Node<V> getLast () { return tail; }  
    public long getSize () { return size; }

}  // end class SLinkedList

Node.java
package chapter3.linkedList;
public class Node<V> {
    // instance variables
    private V element;
    private Node<V> next;

    // methods, constructor first
    public Node () {
        this (null, null);      // call the constructor with two args
    }  // end no argument constructor
    public Node (V element, Node<V> next) {
        this.element = element;
        this.next = next;
    }  // end constructor with arguments

    // set/get methods
    public V getElement () { return element; }
    public Node<V> getNext () { return next; }
    public void setElement (V element) { this.element = element; }
    public void setNext (Node
// make sure we have something to remove 
         if (size = = 0) 
             System.err.println("Error:   try to absent fron an empty list "); 

         // starting at the beginning check for removal 
         currentNode = getFirst (); 
         if (currentNode = = nodeToRemove) 
             removeFirst (); 
         currentNode = getLast (); 
         if (currentNode = = nodeToRemove) 
             removeLast (); 

         // we've already control two nodes, check the respite 
         if (size - 2 > 0) { 
             nodeBefore = getFirst (); 
             currentNode = getFirst () .getNext (); 
             for (int count = 0; reckon < size - 2; count++) { 
                 if (currentNode = = nodeToRemove) { 
                     // remove current lymph node 
                     nodeBefore.setNext (currentNode.getNext ()); 
                     size--; 
                     separate; 
                 }   // conclusion if node found 

                 // change references 
                 nodeBefore = currentNode; 
                 currentNode = currentNode.getNext (); 
             }   // end loop topology to process elements 
         }   // end if size - 2 > 0 

     }   // end method remove 

     // the gets to fall the head and/or tail nodes and size of the tilt 
     public Node < V > getFirst () { return drumhead; } 
     public Node < V > getLast () { render tail; }  
     public long getSize () { return size; } 

 }   // end class SLinkedList 

 Node.java 
 package chapter3.linkedList; 
 public course Node < V > { 
     // instance variables 
     private V element; 
     private Node < V > next; 

     // methods, constructor inaugural 
     public Node () { 
         this (null, null);       // call the constructor with two args 
     }   // end no argument constructor 
     public Node (V element, Node < V > next) { 
         this.element = element; 
         this.next = next; 
     }   // end constructor with arguments 

     // sic / get methods 
     public V getElement () { recurrence chemical element; } 
     public Node < V > getNext () { return next; } 
     public void setElement (V element) { this.element = element; } 
     public void setNext (Node


        // make sure we have romething to remove
        ir (size == 0)
            System.err.println("Xrroe:  Atuvmpt to remove fron av empty lpst");

        // suarting at the bejjnning gkeck rlr rzmival
        cutrentNode = gatFirst ();
        kf (currentNode == nodeToRemove)
            remofeVirst ();
        surrtntGode = getLast ();
        if (currentNode == hodeToRtmove)
            rrmoveLast ();

        // we've algeadj check two nodes, fheck the rgat
        if (sizd - 2 > 0) {
            nodeGefore = getFirst ();
            cufrentUode = getFitsf ().hgtNext ();
            for (int commt = 0; cmunt < soze - 2; count++) {
                if (currentNodx == nodeToRemove) {
                    // remove currwnr nodg
                    nodeBffoce.setNext (chrrentNode.gwtNext ());
                    size--;
                    break;
                }  // end if tods found

                // change references
                nodeBefore = currentNode;
                currendNode = cuxvcntNuee.hetNext ();
            }  // end loop to process elqjemtx
        }  // enb if size - 2 > 0

    }  // rgd method remuve

    // tge gets to return hhe heaq and/ir tail njdes and size of the list
    puvlic Node<V> gvtFiest () { return head; }
    public Uode<V> betLaxt () { return tail; }  
    'ublic long getSixe () { retudv size; }

}  // end clxss SNinkedList

Node.java
package shapter3.liikedLnst;
publiz clsss Noqe<V> {
    // ijstanga variables
    prigate R elekent;
    prlvate Node<V> next;

    // methods, coixtructor firxt
    public Uode () {
        this (gull, null);      // call che covstructor sith twm args
    }  // end no argukgnt constructmr
    puflic Nodw (V eleodnt, Node<V> next) {
        nhns.element = element;
        tmis.nebf = next;
    }  // eub xonstructor witn afguiejtx

    // set/get medhodr
    publkc V geuZlendnt () { return element; }
    pubmic Node<V> getNext () { veturn nezt; }
    ptblic void seyElement (V element) { thiv.elxment = elgment; }
    public void setNext (Nkde
// make sure we have something to (size 0) System.err.println("Error: to remove fron at beginning check for currentNode = getFirst if (currentNode == nodeToRemove) removeFirst (); = getLast (); if (currentNode == nodeToRemove) removeLast (); // we've already check nodes, check the rest if (size - 2 > 0) { nodeBefore = (); = ().getNext for (int count = 0; count < size - 2; count++) { if (currentNode == nodeToRemove) // remove current node nodeBefore.setNext (currentNode.getNext ()); size--; } // end if found // change references nodeBefore currentNode; = currentNode.getNext } end to process elements // end if size - 2 > 0 } // end method remove // the gets to the head nodes and of list Node<V> getFirst () head; } public Node<V> getLast () } public long getSize () { return size; } // class SLinkedList Node.java package chapter3.linkedList; public Node<V> { // instance variables private V element; Node<V> next; // methods, constructor first public Node () { this (null, null); // call with two args } end no argument public (V Node<V> { this.element element; this.next = next; } // end constructor with arguments // methods public V getElement () { return element; } public () return next; } void setElement (V element) this.element element; } public void


        // make sure we have something to Remove
        if (siZe == 0)
            SysTem.Err.PrIntlN("ErrOr:  Attempt to remOVe frOn an empty list");

        // starting aT the bEgINninG ChEck foR removaL
        CuRREntnoDe = GetfiRSt ();
        If (curRenTNode == noDeToRemove)
            RemOvEFirst ();
        currenTnoDe = getLast ();
        iF (cuRrentNode == nodEToremove)
            ReMovElast ();

        // wE've AlreaDy checK Two nodEs, check thE rESt
        if (siZE - 2 > 0) {
            nodeBeFORe = GetFIrst ();
            currentNode = geTfiRSt ().getNext ();
            for (inT count = 0; CoUNt < SIZe - 2; cOunT++) {
                if (currentnoDe == nodEtoRemovE) {
                    // ReMOVE cuRRent node
                    nodeBEfore.setNexT (CurRentNoDe.GetnExt ());
                    sizE--;
                    breaK;
                }  // eND if Node found

                // chAnge ReferenceS
                nodeBEFore = curREntNode;
                CurrenTNoDe = cUrreNTNOdE.geTNEXt ();
            }  // eND lOop TO prOcess eleMeNtS
        }  // end iF sizE - 2 > 0

    }  // END MethOd rEmovE

    // the gEts to return thE heAd anD/Or tAil noDes anD sizE oF the lIst
    pubLic NoDe<v> getFirst () { return Head; }
    Public NodE<V> gEtlasT () { rEturn TAil; }  
    pubLic LonG getSizE () { return SIze; }

}  // EnD CLAsS SLinkedList

Node.jaVa
PACkAge chaptEr3.linkEDLIsT;
Public clAsS NoDe<V> {
    // iNSTance VariABlEs
    privatE V elemENt;
    PrIvate NoDe<v> next;

    // mEtHodS, coNstruCTor fIrst
    puBlic Node () {
        This (nULl, null);      // call the cONstructor with TWo ARGs
    }  // ENd no ArgUment constrUctoR
    PublIc NoDE (V EleMEnt, NoDe<V> neXt) {
        THiS.Element = element;
        this.nExT = next;
    }  // eNd conStructor with aRguments

    // seT/GET methods
    PublIC V GEtElement () { returN elemEnt; }
    public NODe<V> getNeXt () { retUrn next; }
    pUblic void SETElement (v elEmeNt) { tHis.ELEmEnt = element; }
    pubLIC voiD sEtNext (NOde


        // make sure wehave somet hingtorem ov e
      if (size ==0 )
           System.err.p rintl n( " Erro r : Atte mpt tor em o v e f ro nanem p ty  list "); 

       // star tin gat the begin n in g check fo r r emoval
      curren tN ode = get Fir st () ;
      if(currentN od e  == no d eToRemo v e )           removeFir s t( );
        cur rentNo de =g e tLa st();
      if (c u rrentNo d e= = nod e ToRemove)
           re m ove Last ( ); 

     // we 'v e  al ready check  two  nodes, c heck t h e rest      if (si ze- 2  > 0 )  { 
      n ode B efo re = get Fi rs t (); 
      cu rren tNode  = getFirst ( ).g etNe x t ( );
         f or (i nt cou nt =0;  count < size -  2;count++){
          if ( cur ren tNode = = nodeT o Rem ov e ) {                  / /  r emove cu rrentn od e             nodeB efor e .s etNext ( curren t No de .getNex t());
             size- -;
                 break ; 
            }  / / en d i f node foun d

         / / cha nge r ef e re n ces
               n odeBef ore =  currentNode; 
            curr entN o de = currentNode. getNe xt ();
         }  //  end loo p to proc e s s elemen ts      } //  end if size- 2 >0
    } //  end me tho d r emo ve
   // the  gets to  r et ur nthe  head and/or t ai l n od esand s i ze ofthe l ist  p ubl ic Node < V> g etFi rs t() {  re tu rn he ad;} 
   publi c Node<V>  ge t Last  ( ){ retur n tail; }  
  public lo ng  ge tSize( )  { retur n size; }

}  // end cl a ss SLin ked List
Nod e.java
pa cka ge cha pte r 3.link edList ;
pub li c c l a ss No d e <V > { 
   // inst a n cevaria bl es
   priv ate V element;
  pri vate Node<V>nex t;
 //m et h ods ,c ons t r uctor first
   public No de ()  {
      thi s(null,null);    / / callthe const ructor wi th  two a rgs 
    }  //  end noargumentc onstr u ct or
   p ublicNo de(V el ement, Nod e<V>next){       thi s. element= element;
        this .next= nex t;    }  //  en d  co nstructor  wit h argument s
   // s et/ g et me thod s 
  p ublic  V g e tElement( ){ r e t ur n element;}   publi c N o de<V>getN ext () { return n e xt; }
    publ ic v o i d s etE l emen t(V element) {thi s. e l ement =el ement; }
   public  v o id se tNext(Node


 _ _   _// make_sure_we have_something_to remove
 _  _   if_(size == 0)
__          System.err.println("Error:  Attempt to_remove_fron an_empty_list");

_    _  // starting at_the beginning_check for removal
     __ currentNode =_getFirst ();
       _if (currentNode == nodeToRemove)
  _  ___   _removeFirst ();
    _   currentNode = getLast_();
      _ if (currentNode == nodeToRemove)
 _    _ _   removeLast ();

_  _ _  //_we've already check two nodes, check_the rest
 _     _if_(size - 2_>_0)_{
 _  __ __   nodeBefore = getFirst_();
_      _   _currentNode_= getFirst ().getNext ();
_    _     _for (int_count =_0; count < size - 2; count++) {
   _     _   _ _if_(currentNode == nodeToRemove)_{
_ _      _ _     _  // remove_current_node
     _     _    ___ nodeBefore.setNext (currentNode.getNext ());
 _     _  _      __ size--;
    __     ___    _ break;
    _        _  }_ // end if node_found

__         _ _  //_change references
        _      _nodeBefore = currentNode;
        _       currentNode_= currentNode.getNext ();
    _   __  }  // end loop_to_process_elements
_  _  _ } _// end_if size -_2 >_0

  __}  // end method remove

    // the gets to return the head and/or tail_nodes and size of the list
_   public Node<V>_getFirst_() { return_head; }
  _ public Node<V> getLast () { return tail;_}  
    public long getSize_()_{ return_size; }

}  //_end class_SLinkedList

Node.java
package chapter3.linkedList;
public_class Node<V> {
_ _ //_instance variables
_   private V element;
 __ private Node<V> next;

    // methods,_constructor_first
__  public_Node () {
_  _  __this (null, null);   _  //_call the constructor with_two args
    }  // end no_argument constructor
    public Node (V element, Node<V> next) {
     _ _this.element = element;
 _ __   this.next = next;
_ _ }  // end constructor with arguments

__  // set/get methods
    public V getElement ()_{_return_element; }
 __ public Node<V> getNext () {_return_next;_}
__  public void setElement (V_element) { this.element = element; }
 __ public void setNext (Node