All pastes #45609 Raw Edit

zomg

public text v1 · immutable
#45609 ·published 2006-03-14 08:36 UTC
rendered paste body
import java.util.*;

public class TextBlock {

	private Vector TextBlock;

	public TextBlock(){
	    
		this.TextBlock = new Vector();

	}
	
	public void add(char inputCharArray[]){
	    
	    this.TextBlock.add(inputCharArray);
	    
	}
	
	public void traverse(int x, int y, String ancestors){
	   
      char[] someLine = (char[]) this.TextBlock.elementAt(x);         
      Character currentBase = new Character(someLine[y]); 
        
	   if(x==0 && y==0){         
            
         System.out.println(ancestors+currentBase);
            
	   } else if(x==0 && y!=0){ // left
		
         ancestors+=currentBase;
         traverse(x, y-1, ancestors);  
            
		} else if(y==0 && x!=0){ // up
                      
         ancestors+=currentBase;
         traverse(x-1, y,ancestors);  
            
		}  else {
        
         char[] someHigherLine = (char[]) this.TextBlock.elementAt(x-1);
         Character leftChar = new Character(someLine[y-1]);
         Character aboveChar = new Character(someHigherLine[y]);
            
        	int a = currentBase.compareTo(aboveChar);
        	int b = currentBase.compareTo(leftChar);
            
         ancestors+=currentBase;
            
         if(a<b){ // left
                
           traverse(x, y-1,ancestors);     
           traverse(x-1, y,ancestors);
                
         } else { // up
                
           traverse(x-1, y,ancestors);     
           traverse(x, y-1,ancestors);
                
         }
        
     }
     
  }
	
}