# Graph Implementation

Discussion in 'C' started by ihatec, Oct 26, 2010.

1. ### ihatecNew Member

Joined:
Sep 1, 2010
Messages:
20
3
Trophy Points:
0
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[j]=matrix[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)

{
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;

}

for(int i=0; i<count;i++)
{