boolean addRowsToGrid ( List < SquareNode > column , List < SquareNode > ordered ) { for ( int i = 0 ; i < column . size ( ) ; i ++ ) { column . get ( i ) . graph = 0 ; } // now add the rows by traversing down the column int numFirsRow = 0 ; for ( int j = 0 ; j < column . size ( ) ; j ++ ) { SquareNode n = column . get ( j ) ; n . graph = SEARCHED ; ordered . add ( n ) ; SquareNode nextRow ; if ( j == 0 ) { if ( n . getNumberOfConnections ( ) != 2 ) { if ( verbose ) System . err . println ( "Unexpected number of connections. want 2 found " + n . getNumberOfConnections ( ) ) ; return true ; } nextRow = pickNot ( n , column . get ( j + 1 ) ) ; } else if ( j == column . size ( ) - 1 ) { if ( n . getNumberOfConnections ( ) != 2 ) { if ( verbose ) System . err . println ( "Unexpected number of connections. want 2 found " + n . getNumberOfConnections ( ) ) ; return true ; } nextRow = pickNot ( n , column . get ( j - 1 ) ) ; } else { if ( n . getNumberOfConnections ( ) != 3 ) { if ( verbose ) System . err . println ( "Unexpected number of connections. want 2 found " + n . getNumberOfConnections ( ) ) ; return true ; } nextRow = pickNot ( n , column . get ( j - 1 ) , column . get ( j + 1 ) ) ; } nextRow . graph = SEARCHED ; ordered . add ( nextRow ) ; int numberLine = addLineToGrid ( n , nextRow , ordered ) ; if ( j == 0 ) { numFirsRow = numberLine ; } else if ( numberLine != numFirsRow ) { if ( verbose ) System . err . println ( "Number of elements in rows do not match." ) ; return true ; } } return false ; }
Competes the graph by traversing down the first column and adding the rows one at a time