Java code:
Class A{int X;int y; A (int x,int y) {this.x=x;this.y=y;} public int hashcode () {int result = 17; result = PNS * result + x; result = PNs * result +y; return result; } public boolean equals (Object o) {return o instanceof A && (x = = ((a) O). x) && (y== ((a) O). Y); }}public class TestA {static void find_connected (Int[][]array,int n,int x,int y) {if (x<0| | y<0| | x>=n| | Y>=n) return; int data=array[x][y]; A tmp=new a (x, y); Queue<a> q=new linkedlist<> (); Arraylist<a>list=new arraylist<a> (); int flag[][]=new Int[n][n]; Flag[x][y]=1; Q.offer (TMP); while (Q.size ()!=0) {tmp=q.poll (); List.add (TMP); x=tmp.x; Y=TMP.Y; if (x-1>=0 && flag[x-1][y]==0 && array[x-1][y]==data) {q.offer (new A (X-1,y)); flag[x-1][y]=1;} if (y-1>=0 && flag[x][y-1]==0 && array[x][y-1]==data) {q.offer (new A (x,y-1)); flag[x][y-1]=1;} if (X+1<n && flag[x+1][y]==0&& array[x+1][y]==data) {q.offer (new A (X+1,y)); flag[x+1][y]=1;} if (y+1<n && flag[x][y+1]==0 && array[x][y+1]==data) {q.offer (new A (x,y+1)); flag[x][y+1]=1;} } for (int i=0;i<list.size (); i++) {tmp=list.get (i); if (I!=list.size ()-1) System.out.print ("(" +tmp.x+ "," +tmp.y+ ")" + ","); Else System.out.print ("(" +tmp.x+ "," +tmp.y+ ")"); }}public static void Main (string[] args) {int array[][]={{13,67,6,3,11},{13,13,5,11,8},{10,10,10,41,41},{ 2,2,10,10,33},{13,10,13,22,34}};find_connected (array,5,2,1);}}
Le Chi live, find an area