具体实现代码如下:
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;
}