Hi! I'm not that good at programming, so I was wondering if anyone could tell me why I'm getting an unreachable statement error for lines 18, 35, 68, and 86.
Any input is greatly appreciated!
Code:
import java.util.ArrayList;
public class Graph {
ArrayList<ArrayList<Integer>> graph;
public void Graph( int n )
{
graph = new ArrayList<ArrayList<Integer>>(n);
}
public boolean connect( int add1, int add2 )
{
if( add1 >= graph.size() || add2 >= graph.size()
|| add1 == add2 )
{
throw new IllegalArgumentException();
return false;
} else if( graph.get(add1).contains( new Integer(add2) ) ||
graph.get(add2).contains( new Integer(add1) ) )
{
return false;
} else {
graph.get(add1).add( new Integer(add2) );
graph.get(add2).add( new Integer(add1) );
return true;
}
}
public boolean disconnect( int dis1, int dis2 )
{
if( dis1 >= graph.size() || dis2 >= graph.size() )
{
throw new IllegalArgumentException();
return false;
} else if( !graph.get(dis1).contains( new Integer(dis2) ) ||
!graph.get(dis2).contains( new Integer(dis1) ) )
{
return false;
} else {
graph.get(dis1).remove( new Integer(dis2) );
graph.get(dis2).remove( new Integer(dis1) );
return true;
}
}
public boolean areConnected( int adj1, int adj2 )
{
if( adj1 >= graph.size() || adj2 >= graph.size() )
{
throw new IllegalArgumentException();
}
if( graph.get(adj1).contains( new Integer(adj2) ) &&
graph.get(adj2).contains( new Integer(adj1) ) )
{
return true;
} else {
return false;
}
}
public ArrayList<Integer> adjacencies( int node )
{
if( node >= graph.size() )
{
throw new IllegalArgumentException();
return null;
}
ArrayList<Integer> hold = new ArrayList<Integer>(graph.size());
for( int i = 0; i > graph.get(node).size(); i++ )
{
hold.set(i,graph.get(node).get(i));
}
return hold;
}
public int degree( int node )
{
if( node >= graph.size() )
{
throw new IllegalArgumentException();
return 0;
}
return graph.get(node).size();
}
public boolean isEmpty()
{
return graph.size() == 0;
}
}
Any input is greatly appreciated!
Comment