int net[]={1,2,2,1,3,3,4,4};
bool CheckBox(int net[], int n)
{
Stack<int> *s=new Stack<int>(n);
for(int i=0; i<n;i++)
{
if(!s->IsEmpty())
{
if((net[i]==net[s->Top()])
{
int x;
s->Delete(x);
}
else
s->Add(i);
}
else
s->Add(i);
}
// 是否有不可布线的网组
if(s->IsEmpty())
{
delete s;
cout<<"Switch box is routable"<<endl;
return true;
}
delete s;
cout <<"Switch box is not routable"<<endl;
return false;
}
Ref:<<数据结构,算法与应用>>P176~178