fork download
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. struct Node
  5. {
  6. Node(int i): i_(i) {}
  7. int i_;
  8. };
  9.  
  10. class FSM{
  11. private:
  12. std::vector<Node> nodeList;
  13. int cap;
  14. int obs;
  15. int topNode;
  16.  
  17. public:
  18. FSM(int nodeCap, int numObs){
  19. cap = nodeCap;
  20. obs = numObs;
  21. topNode = -1;
  22. }
  23.  
  24. bool addNode(){
  25. if (isFull()) return false;
  26. nodeList.push_back(Node(obs));
  27. topNode++;
  28. return true;
  29. }
  30.  
  31. bool isFull() { return obs >= cap ? true : false; }
  32.  
  33. void printNodeLocations()
  34. {
  35. for(Node& n : nodeList) { std::cout << &n << std::endl; }
  36. }
  37. };
  38.  
  39. int main()
  40. {
  41. FSM machine(2, 0);
  42. machine.addNode();
  43. machine.addNode();
  44. machine.printNodeLocations();
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
0x8ad3018
0x8ad301c