求java大神!下面是一个用java表示图的程序(邻接表表示法);在运行的时候提示NullPointerException.
程序如下
packagegraph;
classLink
{
publicintidata;
publicdoubleddata;
publicLinknext;
//.
publicLink(intid,doubledd)
{
idata=id;
ddata=dd;
}
//.
publicvoiddisplayLink()
{
System.out.println("{"+idata+","+ddata+"}");
}
}//endclassEdge
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
classgraphHead
{
//intj;
Linkfirst;
//.
publicgraphHead()
{
first=null;
}
//.
publicbooleanisEmpty()
{
return(first==null);
}
//.
publicvoidinsertFirst(intid,doubledd)
{
LinknewLink=newLink(id,dd);
newLink.next=first;
first=newLink;
}
}//endclassgraphHead
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
publicclassisGraph{
publicstaticfinalintN=10;//ps:thisnumbershouldbetoldatfirst
publicgraphHead[]ADTGraph=newgraphHead[N];
//.
publicvoidaddEdge(intfrom,intto)
{
ADTGraph[from-1].insertFirst(to,0.0);
ADTGraph[to-1].insertFirst(from,0.0);
}
//.
publicvoiddisplayGraph()
{
inti;
for(i=0;i