What words do not say, on the bar code, the code I added a note.
cn.lu.linklist Package;
// way linked list class
public class LinkList <T> {
Private the Cell <T> First; // chain header defines
// new non-empty chain configuration parameters
public LinkList () {
First = new new the Cell <T> ; ()
}
// methods belt configuration parameters (tail additive method)
public LinkList (T [] Data ) {
first = new new the Cell <T> (); // first node
Cell <T> end = First;
the Cell <T> TEMP = null ;
// the parameter passed chain
for(T T: Data) {
TEMP = new new the Cell <T> (); // be new, otherwise, the final not empty temp.next
temp.setData (T);
end.setNext (TEMP);
End = TEMP;
}
}
// specified position in the chain to insert data
public Boolean iNSERT (T T, int index) {
int COUNT = 0 ;
the Cell <T> = First pointer; // define a pointer variable
the Cell <T> TEMP = null ; // temporary variable
// insertion position value chain is not less than 1 (the default chain has been the head node)
IF (index <. 1 )
the throw new new An ArrayIndexOutOfBoundsException ();
// pointer to a specific position (before a default value position index starting from 0)
the while (pointer =! Null && COUNT <index - . 1 ) {
pointer = pointer.getNext ();
COUNT ++ ;
}
// pointer location is empty on the error (chain length beyond the insertion position)
IF (pointer == null )
the throw new new An ArrayIndexOutOfBoundsException ();
// data is inserted at the specified location
the else {
TEMP = new new Cell <T>();
Temp.setData (T); // need to insert data assigned to a temporary variable
temp.setNext (pointer.getNext ()); // the data to be inserted in the next index points to the location data
pointer.setNext (temp) ; // the next pointer pointing to the location data to be inserted
}
return to true ;
}
// in the chain to delete the specified position data
public Boolean remove ( int index) {
int COUNT = 0 ;
the Cell <T> = First pointer; / / definition of a pointer variable
the Cell <T> TEMP = null ; // definition of temporary variables
// to delete location not less than 1 chain
IF (index < . 1 )
the throw new new An ArrayIndexOutOfBoundsException ();
// pointer to a specific position (before a default value position index starting from 0)
the while (! pointer = null && COUNT <index - . 1 ) {
pointer = pointer.getNext ();
COUNT ++ ;
}
// to delete data position exceeds the length of the chain
IF (pointer == null )
the throw new new an ArrayIndexOutOfBoundsException ();
// delete data operation start
the else {
TEMPPointer.getNext = (); // temporary variables assigned to the data to be deleted
pointer.setNext (temp.getNext ()); // the next data current pointer points to the next data is data to be deleted
}
return to true ;
}
/ / replacement data location specified
public Boolean replace ( int index, T T) {
int COUNT = 0 ;
the Cell <T> = First pointer; // define a pointer variable
// to replace the chain location can not be less than. 1
IF (index < . 1 )
the throw new new An ArrayIndexOutOfBoundsException ();
// pointer to the location to be replaced
while(! pointer = null && COUNT < index) {
pointer = pointer.getNext ();
COUNT ++ ;
}
// determines whether the current pointer position can not exceed the length of the chain
IF (pointer == null )
the throw new new An ArrayIndexOutOfBoundsException ();
// replace data starts to operate
the else {
// Note that this case does not change next pointer value, but replaces the data pointer to t.
pointer.setData (T);
}
return to true ;
}
// get the value of the specified position data link
public T GET (int index) {
int COUNT = 0 ;
the Cell <T> = First pointer; // define a pointer variable
// to replace the chain location can not be less than. 1
IF (index < . 1 )
the throw new new An ArrayIndexOutOfBoundsException ();
// pointer to designated position
the while (pointer =! null && COUNT < index) {
pointer = pointer.getNext ();
COUNT ++ ;
}
// determines whether the current pointer position can not exceed the length of the chain
IF (pointer == null )
the throw new new An ArrayIndexOutOfBoundsException ();
the else
return pointer.getData ();
}
// determines whether the data link is null
public Boolean isEmpty () {
IF (first.getNext () == null )
return to true ;
return to false ;
}
// Calculation data chain length
public int size () {
int COUNT = 0 ;
the Cell <T> = First pointer; // definition of indicator variables
the while (! pointer.getNext () = null ) {
pointer= Pointer.getNext ();
COUNT ++ ;
}
return COUNT;
}
// chain toString method
public String toString () {
String STR = " [ " ; // start code output
the Cell <T> = pointer First;
/ / move the pointer conditional loop
the while (pointer =! null ) {
pointer = pointer.getNext (); // move the pointer
// pointer position is not able to empty
IF (pointer =! null ) {
//When the next output pointer is not null position.
IF (! pointer.getNext () = null ) {
STR = pointer.getData STR + () + " , " ;
}
// When a pointer location is empty
the else {
STR = + STR pointer.getData ();
}
}
}
STR = STR + " ] " ; // terminator output
return STR;
}
}