c++ - How do I clear list of pair -


i want clear adj list main function each test case.

class graph { long long int v;    // no. of vertices list< pair<long long int,long long int> > *adj;  public: graph(long long int v);  // constructor  //clear previous values void clearlist(); }; void graph::clearlist() { //what should write here } 

well, since it's pointer list, should check existence first. , need decide if want keep object it's pointing after clear it, clear it:

void graph::clearlist() {     if ( adj ) {         adj->clear();     } } 

edit: couple of side notes depending on you're doing... if number of vertices member variable v what's in list, use adj->size() that. should consider not using pointer list , using list directly avoid manual lifetime management of adj in graph. finally, constructor implies you're declaring number of vertices front, maybe container more suitable, vector?


Comments

Popular posts from this blog

cookies - Yii2 Advanced - Share session between frontend and mainsite (duplicate of frontend for www) -

angular - password and confirm password field validation angular2 reactive forms -

php - Permission denied. Laravel linux server -