Questions about std::list C++ -
i'm new whole stl business , have 1 question. before using stl list nodes :
class node { int duration; string name; node * next; node * previous; };
so question when m use stl need node * next
, node * previous
or useless since std::list makes ammend them own next , previous functions?
and 1 more question, guys prefer using std::list or making own? because gonna first time using std::list , im quite buffled.
thanks time.
no don't need next
, previous
, std::list
implements internally whole linked list mechanism. just:
class node { int duration; string name; };
and define list as:
std::list<node> mylist;
even better use std::vector
instead of std::list
outperforms in situations std::list
renders more cache friendly.
std::vector<node> myvec;
another option use std::pair
instead of defining own struct
:
std::list<std::pair<int, std::string>> mylist;
however, use of std::pair
here cleary subjective. find more handy use std::pair
instead of defining struct
s 2 member variables, due fact can see element type of stl data-structure @ place defined.
Comments
Post a Comment