There is a grid.
static Double [][] myTiles = new Double[row][column];
The goal is to connect each tile with an adjacent tile. Compare a value between the pair, construct a link between tiles to create the minimum spanning tree for a given grid.
Below is my initial approach to this issue:
Nine ( 9 ) groups of tiles are identified.
These groups have the same logic and the same availability of adjacent squares.
For each cell in my grid I decided to check a cell above, below, to the left and to the right. Certain cells cannot perform all checks when located on an edge of the grid. Below is the movement representation for each type of a tile.
My current solution is a nested for-loop with the below if-else statements:
if ( row == 0 && column == 0) {
mySortingQueue.offer(createEdgeSouth(myEdge, myTiles, row, column));
mySortingQueue.offer(createEdgeEast(myEdge, myTiles, row, column)); }
else if ( row == 0 && ( column > 0 && column < myTiles.length ) ) {
mySortingQueue.offer(createEdgeSouth(myEdge, myTiles, row, column));
mySortingQueue.offer(createEdgeEast(myEdge, myTiles, row, column));
mySortingQueue.offer(createEdgeWest(myEdge, myTiles, row, column)); }
else if ( row == 0 && column == myTiles.length ) {
mySortingQueue.offer(createEdgeSouth(myEdge, myTiles, row, column));
mySortingQueue.offer(createEdgeWest(myEdge, myTiles, row, column)); }
else if ( ( row > 0 && row < myTilese[row].length ) && column == 0 ) {
mySortingQueue.offer(createEdgeSouth(myEdge, myTiles, row, column));
mySortingQueue.offer(createEdgeEast(myEdge, myTiles, row, column));
mySortingQueue.offer(createEdgeNorth(myEdge, myTiles, row, column)); }
else if ( row == myTilese[row].length && column == 0 ) {
mySortingQueue.offer(createEdgeEast(myEdge, myTiles, row, column));
mySortingQueue.offer(createEdgeNorth(myEdge, myTiles, row, column)); }
else if ( row == myTilese[row].length && ( column > 0 && column < myTiles.length ) ) {
mySortingQueue.offer(createEdgeNorth(myEdge, myTiles, row, column));
mySortingQueue.offer(createEdgeEast(myEdge, myTiles, row, column));
mySortingQueue.offer(createEdgeWest(myEdge, myTiles, row, column)); }
else if ( row == myTilese[row].length && column == myTiles.length ) {
mySortingQueue.offer(createEdgeNorth(myEdge, myTiles, row, column));
mySortingQueue.offer(createEdgeWest(myEdge, myTiles, row, column)); }
else if ( ( row > 0 && row < myTilese[row].length ) && column == myTiles.length ) {
mySortingQueue.offer(createEdgeNorth(myEdge, myTiles, row, column));
mySortingQueue.offer(createEdgeWest(myEdge, myTiles, row, column));
mySortingQueue.offer(createEdgeSouth(myEdge, myTiles, row, column));}
else {
mySortingQueue.offer(createEdgeNorth(myEdge, myTiles, row, column));
mySortingQueue.offer(createEdgeEast(myEdge, myTiles, row, column));
mySortingQueue.offer(createEdgeWest(myEdge, myTiles, row, column));
mySortingQueue.offer(createEdgeSouth(myEdge, myTiles, row, column));}
The above logic creates at least two links and at most four. That's a lot of diplicates to sort when it comes to building a minimum spanning tree.
Is there an eloquent way of representing the above if-else block?