fork download
  1. #include <iostream>
  2. #include <list>
  3. #include <string>
  4. #include <map>
  5.  
  6. using namespace std;
  7.  
  8. struct node {
  9. map<string,double> candidates;
  10. double pathCost;
  11. string source;
  12. };
  13.  
  14. void addNode(list<node*> &nodeKeeper, string source, double pathCost )
  15. {
  16. node* newNode = new node;
  17. newNode->source = source;
  18. newNode->pathCost = pathCost;
  19.  
  20. nodeKeeper.push_back(newNode);
  21. }
  22.  
  23. int main()
  24. {
  25. std::list<node*> nodeKeeper;
  26.  
  27. int sizeOfList = 10;
  28. for( int i =0; i < sizeOfList; i++) {
  29. addNode(nodeKeeper, "test", i);
  30. }
  31.  
  32. for( int i =0; i < sizeOfList; i++) {
  33. node * temp = nodeKeeper.back();
  34.  
  35. cout << temp->pathCost << endl;
  36.  
  37. //free the memory
  38. delete temp;
  39. //get rid of it from the list
  40. nodeKeeper.pop_back();
  41. }
  42. }
Success #stdin #stdout 0s 2988KB
stdin
Standard input is empty
stdout
9
8
7
6
5
4
3
2
1
0