Hi, I have to implement a graph as a adjacent matrix for my algorithms & data structure course and almost everything works correct besides method given below. The method should removes given vertex from the graph and all the edges containing it.

Returns: 0 if no error occurs or -1 otherwise

It does not produce the proper output(does not remove the given vertex and edges). I even draw and analize this step by step on a paper and I thing there is a problem with the part

if(i==vertex||j==vertex)

continue;

array[i][j]=matrix[i][j];

but I am not sure that this is the problem, maybe it is somewhere else. Please help me with this.

Returns: 0 if no error occurs or -1 otherwise

It does not produce the proper output(does not remove the given vertex and edges). I even draw and analize this step by step on a paper and I thing there is a problem with the part

if(i==vertex||j==vertex)

continue;

array[i][j]=matrix[i][j];

but I am not sure that this is the problem, maybe it is somewhere else. Please help me with this.

Code:

count - size of the adjacent matrix(number of vertices) adjacent[i][j] - matrix representing the graph.(from this graph vertex should be removed) int AdjacencyMatrixGraph::removeVertex(int vertex) { if(vertex>=count||vertex<0) return -1; if(count==0) return -1; else { int **tablica=new int*[count-1]; for(int i=0;i<count-1;i++) tablica[i]=new int[count-1]; if(!tablica) return -1; for(int i=0;i<count-1;i++) for(int j=0;j<count-1;j++) tablica[i][j]=0; for(int i=0;i<count-1;i++) for(int j=0;j<count-1;j++) { if(i==vertex || j==vertex) continue; tablica[i][j]=adjacent[i][j]; } for(int i=0; i<count;i++) { delete [] adjacent[i]; } delete [] adjacent; adjacent=tablica; count--; return 0; } }

*Last edited by shabbir; 27Oct2010 at 08:18.. Reason: Code blocks*