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
Post a Comment