if we are having code already written for our stl containers then why are we learning to write the stl codes of various containers , will they be any useful once we are done with the course and then after that doing questions from various platforms.
Query regarding usage of stl containers
if we are having code already written for our stl containers then why are we learning to write the stl codes of various containers , will they be any useful once we are done with the course and then after that doing questions from various platforms.
Please reply fast…
yeah bro,
it will be very helpful, and in 60-70% of the problems,you will have to write ur own logic to make stl work as per ur requirement.
so you must learn it.
If i had included the header file list in our program and now i had defined a node class in my code containing data and next pointer. I have a object n of the node class. So now my question is that can i use the stl functions in my object n like push_back etc or again i had to create functions like push_back to be used in my object seperately.
no it will work, no need to create your own function
So according to you,
#include
class node{
Int data;
node* next;
}
Int main()
{
node*n;
n.push_back(5);
n.push_back(6);
return 0
}
will work?
Am i getting it right
In starting it is list header file
push_back function is a function of vector , so if ur node class contains vector then u can use it .
like
class p{
public:
vector< int> v;
};
p c;
c.v.push_back(2)
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.