borisbn

kill vector

Mar 22nd, 2013
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using std::cout;
  6. using std::endl;
  7.  
  8. #define N 30000
  9. typedef unsigned int uint;
  10. class Node;
  11. class Edge;
  12. std::vector<Node*> nodes;
  13. std::vector<Edge*> edges;
  14.  
  15. class Node
  16. {
  17. public:
  18.     Node(uint id): id(id)
  19.     {
  20.         nodes.push_back(this);
  21.     }
  22. public:
  23.     uint id;
  24. };
  25.  
  26. class Edge
  27. {
  28. public:
  29.     Edge(int nod1, int nod2)
  30.         : nodH(nod1), nodT(nod2)
  31.     {
  32.         edges.push_back(this);
  33.     }
  34. /*
  35.     bool Connects(Node* nod1, Node* nod2)
  36.     {
  37.         return (
  38.             (nod1->id == this->nodH && nod2->id == this->nodT) ||
  39.             (nod1->id == this->nodT && nod2->id == this->nodH));
  40.     }
  41. */
  42. public:
  43.     int nodH;
  44.     int nodT;
  45. };
  46.  
  47. template< class T >
  48. void clearVector( std::vector< T > & v )
  49. {
  50.     std::vector< T > dummy;
  51.     std::swap( v, dummy );
  52. }
  53.  
  54. struct die {
  55.     template <class T> void operator()( const T * p ) const { delete p; }
  56. };
  57. template< class InputIterator >
  58. inline void kill_em_all( const InputIterator & begin, const InputIterator & end )
  59. {
  60.     std::for_each( begin, end, die() );
  61. }
  62.  
  63. int main()
  64. {
  65.     Node *nd;
  66.     for(long int i=0;i<N;i++)
  67.     {
  68.         for (int j=0;j<N;j++)
  69.         {
  70.             nd = new Node(j);
  71.         }
  72.         for (uint j=0;j<N;j++)
  73.         {
  74.             Edge* e = new Edge(j,N-j);
  75.         }
  76.         if ( i % 1000 == 0 ) {
  77.             cout << i << endl;
  78.         }
  79.         //kill_em_all( nodes.begin(), nodes.end() );
  80.         //kill_em_all( edges.begin(), edges.end() );
  81.         //clearVector( nodes );
  82.         //clearVector( edges );
  83.     }
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment