fork download
  1. // switch box routing
  2.  
  3. #include <iostream.h>
  4. #include "stack.h"
  5.  
  6. bool CheckBox(int net[], int n)
  7. {// Determine whether the switch box is routable.
  8. Stack<int> *s = new Stack<int> (n);
  9.  
  10. // scan nets clockwise
  11. for (int i = 0; i < n; i++) {
  12. // examine net[i]
  13. if (!s->IsEmpty()) {// check with top net
  14. if (net[i] == net[s->Top()]) {
  15. // net[i] routable, delete from stack
  16. int x;
  17. s->Delete(x);}
  18. else s->Add(i);}
  19. else s->Add(i);
  20. }
  21.  
  22. // any unrouted nets left?
  23. if (s->IsEmpty()) {// no nets remain
  24. delete s;
  25. cout << "Switch box is routable" << endl;
  26. return true;}
  27.  
  28. delete s;
  29. cout << "Switch box is not routable" << endl;
  30. return false;
  31. }
  32.  
  33. void main(void)
  34. {
  35. int *net, n;
  36. cout << "Type number of pins in switch box " << endl;
  37. cin >> n;
  38. try {net = new int [n];
  39. cout << "Type net numbers for pins 1 through " << n << endl;
  40. for (int i = 0; i<n; i++) cin >> net[i];
  41. CheckBox(net, n);}
  42. catch (NoMem)
  43. {cout << "Insufficient memory" << endl;}
  44. }
  45.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:22: fatal error: iostream.h: No such file or directory
compilation terminated.
stdout
Standard output is empty