All pastes #746089 Raw Edit

Someone

public text v1 · immutable
·published 2007-10-22 22:51 UTC
rendered paste body
public myDLNode <T> search(T e) {
	myDLNode<T> index; 
    boolean found;
	index = head;   
    found = false;   
	while(index != null && !found) { 
    	if(index.getElement() == e) {  
        	found = true;
        } else {
            index = index.next; 
        }
	}                         
return index;	
}// – searches for the first occurrence of element e in the linked list. It returns the corresponding node in the list; O(n)

public myDLNode <T> searchAfter(myDLNode <T> p, T e) throws InvalidPositionException {	
	if((p == null) || (p == tail)) {
 		throw new InvalidPositionException("searchAfter.");
 	}
	myDLNode<T> index; 
    boolean found;
	index = tail;   
    found = false;	
	while(index != p && !found) { 
    	if(index.getElement() == e) {  
        	found = true;
        } else {
            index = index.prev; 
        }
	}                         
return index;
}// throws InvalidPositionException – searches for the first occurrence of element e after node p (not including node p). It returns the corresponding node in the list

public myDLNode <T> searchBefore(myDLNode <T> p, T e) throws InvalidPositionException {
	if((p == null) || (p == head)) {
 		throw new InvalidPositionException("searchBefore.");
 	}
	myDLNode<T> index; 
    boolean found;
	index = head;   
    found = false;	
	while(index != p && !found) { 
    	if(index.getElement() == e) {  
        	found = true;
        } else {
            index = index.next; 
        }
	}                         
return index;
}// throws InvalidPositionException – searches for the first occurrence of element e before node p (not including node p). It returns the corresponding node in the list.

public myDLNode<T> searchAfter(myDLNode <T> p, T e, int i) throws InvalidPositionException {
	if((p == null) || (p == tail)) {
 		throw new InvalidPositionException("searchAfter.");
 	}
	myDLNode<T> index; 
    int found;
	index = tail;   
    found = 0;	
	while(index != p && found != i) { 
    	if(index.getElement() == e) {  
        	found++;
        } else {
            index = index.prev; 
        }
	}                         
return index;	
}// - searches for the ith occurrence of element e in the linked list after node p and not including p. It returns the corresponding node in the list.