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.
Query regarding stl containers
@Parmeet-Kalsi-1631789033630118 header file <list> will contain all functions related to lists, so if you include it in the program and you define a list object, you can use all the STL functions on the list object.
You cannot use STL list functions on an object of a class that you defined.
Dont forget to mark your doubt as resolved.
since solving majority questions we need to define our own class and object , so do we need to write functions already present in c++ stl again for our user defined class such as push_back etc, and if it is so then won’t it become hectic in large problems to define our own linked list class and write the functions.
@Parmeet-Kalsi-1631789033630118 there are STL for most data structures, so if you want to use STL functions, just use the STL data structures also.
i don’t think this is the answer to my question
@Parmeet-Kalsi-1631789033630118 if you are talking about data structures like trees and graphs then obviously you need to write your own functions, but its not that hectic because you dont need all the functions for all the questions. For other basic data structures like lists, hashmaps, heaps, stacks, etc STL exists.
lets say i have i simple linked list question in which i have to find the middle node of the linked list,so
how can i do this question by just using c++ stl and not by creating our own class and functions corresponding to it?
is it possible
@Parmeet-Kalsi-1631789033630118 yeah it is possible, just declare a <list> object and use the available STL functions. You CAN use your own functions too if need be… Have I answered your doubt now?
yeah
thanks now i think i am satisfied