lundi 18 novembre 2019

Indepth Explanation on Array Of Arrays

   `public class Graph {
    int edges [][];
    public Graph(int[][] edges){
    this.edges = edges;
     }
    public Graph looseEdges(int i, int j){
    int n = edges.length;
    int[][] neeedges =new int[n][];
    for (int k=0; k<n; ++k) {

        edgeList:{
        int z;
        search:{
            if (k==i){
                for (z=0; z< edges[k].length; ++z){
                    if (edges[k][z]==j)break search;
                }else if(k==j){
                    for (z=0; z<edges[k].length; ++z){
                        if (edges[k][z]==i)break search;
                    }
                }//No edge to be deleted;share this list.
                neeedges[k]= edges[k];
                break edgeList;
            }
        }//search copy the list, omitting the edge at position z
            int m = edges[k].length-1;
        int ne []= new int[m];
        System.arraycopy(edges[k],0,ne,0,z);
        System.arraycopy(edges[k],z+1,ne,z,m-z);
        neeedges[k]= ne;
        }//edgelist
    }return new Graph(neeedges);
  }
  }`

I need someone to kindly explain to me step by step how this array work. Secondly i always get java exception when using else if statement(is there another form to write the else if statement with java throwing an exception?)

Aucun commentaire:

Enregistrer un commentaire