in inertatbottom function in the video the datatype of x is passed as int but actually we do not know the datatype of x before because the class as templated what to do to pass the datatype of x as t?
Stack reverse using recursion issue
You can directly pass T instead of int, or any datatype of your class is template type. The compiler resolved it during the runtime
eg:
void print(T data){
cout << data <<endl;
}
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.
thanku mam for answering.in addition would it be ok if u tell me about how to make a templated function.give an example.
template<typename T>
class Graph{
map<T , list<T>> adjList;
public:
Graph(){
}
void addEdge(T u , T v , bool isBir = true){
adjList[u].push_back(v);
if(isBir)
adjList[v].push_back(u);
}
};
int main(){
Graph<int> g;
g.addEdge(1,2);
g.addEdge(100,2);
g.addEdge(100,3);
}
mam u have wriiten the addedge function inside the graph class what if we have to do the same thing outside the class and we are using inbuilt library for stack
@Rj.25 hey ye code dekho isme mene template se stack bnaya hai that you want:
Also app sedha T x; krke variable le skte hai.
@Rj.25
simply function ke uppar
yeh syntax use kar lo
u needed a example so i gave it for a class
template<typename T>
void f(T s)
{
std::cout << s << '\n';
}
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.