Two Corrections: In the range for-loop on line 32, it has to be "T nbr" not "int nbr". This is because we cannot assume the type to be int since we are abstracting it away under the template T. On line 21, the "visited" map should be "map visited" and not "map visited".
@PrashantKumarSharma3 жыл бұрын
There are too many errors in his code. This is one of them
@lostparadise70283 жыл бұрын
map visited will come in bfs function instead of "map visited;"...It works same anyways,But..
@ansumanmishra17574 жыл бұрын
The slight change in order is because in the input(in main func) there is no edge for (0,3) . After adding an edge you will get the output as 0 1 3 2 4 5
@josejayant944 жыл бұрын
It worked
@piyushbajaj83554 жыл бұрын
yes
@lydialarina Жыл бұрын
I was very confused by the topic, and even though I found examples of code online, I really needed a thorough walkthrough. Excellent explanation! Thank you so much!
@arpitkhandelwal60503 жыл бұрын
if we are using generic programming here then why are we writing addEdge(int x, int y) instead of addEgde(t x, t y)? if we pass string to this function this will give us an error.
@mavericmadhav3 жыл бұрын
Two issues found in this Implementation: 1) addEdge method takes int as arg type instead of Template type T. It needs to be fixed 2) addEdge for 0-3 was Missing due to which the. Order output came different than expected. Thanks for the explanation though. It was very clear.
@praveensingh17118 ай бұрын
Explained well.😊 keep it up
@ce050manankadiya72 жыл бұрын
Nice explanation sir 👍
@-invisibleguest-1883 жыл бұрын
theory part is good enough ,I understand it perfectly . -> but implementation part is little bit tricky and for me it was very hard to understand coz I learned it by using array in my University. -> note: i am seeing this video without maintaining the playlist may be for that it seemed confuse to me .
@imkd4real2 жыл бұрын
I will cry u explained it so well
@alishachhabra79954 жыл бұрын
Very well explained!
@rohitmathur97234 жыл бұрын
Amazing Explanation!
@jatinkumar44102 жыл бұрын
nice explanation
@joaovictormelo64423 жыл бұрын
I would like to know if I can change t in the map visited by bool.
@saurabhsaxena19922 жыл бұрын
Thanks sir
@yogeshsarowgi75994 жыл бұрын
in line no. 32 for(int nbr : l[node]) why you are using int?? What if value is string because you make generic class
@gouravgoel29744 жыл бұрын
then you can use string in place of int.
@yogeshsarowgi75994 жыл бұрын
@@gouravgoel2974 then what is the use of generic??....it should be T
@pratyushranjan4254 жыл бұрын
@@yogeshsarowgi7599 yepp it should be T
@pr0mero8172 жыл бұрын
You are clouding the namespace by using namespace std. pls try the compiler trick
@akash-lz2dq3 жыл бұрын
when you are using map for visited record then you are increasing the time complexity ,because map takes o(logn) to look up and array takes only 1 constant time ,
@akash-lz2dq3 жыл бұрын
but if the node is of alphabatic notation or string then we cant use array thanks i got it
@Ben-pb7ct4 жыл бұрын
Could anyone explain what is for(int nbr : l[node])? Does this mean if the integer nbr in l[node] then the loop keeps going down? and where I could find the use about this : ( please help
@thienbinhinh79414 жыл бұрын
you can search for "advanced loop"
@programmer40424 жыл бұрын
kzbin.info/www/bejne/mYSrYpejbsmLfq8
@tombrady73903 жыл бұрын
range-based for loop gfg
@helloworld89123 жыл бұрын
My code is running for infinite "if(! visited [nbr])" is not working. Please help
@sindhumathi92093 жыл бұрын
Can u pls explain the Find Shortest Path using BFS
@giwrgoscy294 Жыл бұрын
THANKS MOOOOOOM
@ishitasinghal672 жыл бұрын
How can we print levels using this approach?
@090-jellabharath23 жыл бұрын
Tq sir
@uditkotecha26363 жыл бұрын
Nice
@vamshisamineniz59054 жыл бұрын
could u please put the source code in the above description
@amitkumar_ara2 жыл бұрын
#include using namespace std; template class Graph { private: map l; public: void addEdge(int x, int y) { l[x].push_back(y); l[y].push_back(x); } void bfs(T src) { map visited; queue q; q.push(src); visited[src] = true; while (!q.empty()) { T node = q.front(); q.pop(); cout
@binunath55252 жыл бұрын
In line no 35 error shown that end1 was not declared in this scope
@ashwanikumarsingh82323 жыл бұрын
sir line no 9 me error aa raha hai error: template argument 2 is invalid
@ayushpandey86334 жыл бұрын
if(!visited[nbr]) its initializing also internally that too false ??? ie nbr:false
@osiris11023 жыл бұрын
I think that would be visited[nbr] = false;
@sakshamp44883 жыл бұрын
Can anyone tell me why he gas written Visited(src)=true.just not able to understand:(
@NavneetKaur-vt8kt2 жыл бұрын
because src is the starting point of traversal, hence we mark it as true
@tanmaychandra94343 жыл бұрын
Sir will use of unordered_map() perform better than map() ?
@nitinsinghrawat68913 жыл бұрын
yes
@nitinsinghrawat68913 жыл бұрын
But listen in order to avoid the duplicate key in a list we use the map instead of the unordered map
@md.salauddin3 жыл бұрын
how to get user input???
@sagarjain41282 жыл бұрын
we get user input by using Adjacency matrix.
@shikharjaiswal68772 жыл бұрын
10 | map l ; | ^~~~ BFS_Graph.cpp:3:1: note: 'std::list' is defined in header ''; did you forget to '#include '? 2 | #include +++ |+#include 3 | BFS_Graph.cpp:10:13: error: template argument 2 is invalid 10 | map l ; | ^ BFS_Graph.cpp:10:13: error: template argument 4 is invalid BFS_Graph.cpp:10:14: error: expected unqualified-id before '>' token 10 | map l ; | ^~ BFS_Graph.cpp: In member function 'void BFS_Graph::addEdge(int, int)': BFS_Graph.cpp:14:5: error: 'l' was not declared in this scope 14 | l[x].push_back(y); | ^ BFS_Graph.cpp: In member function 'void BFS_Graph::bfs(T)': BFS_Graph.cpp:21:5: error: 'queue' was not declared in this scope 21 | queue q; | ^~~~~ BFS_Graph.cpp:3:1: note: 'std::queue' is defined in header ''; did you forget to '#include '? 2 | #include +++ |+#include 3 | BFS_Graph.cpp:21:12: error: expected primary-expression before '>' token 21 | queue q; | ^ BFS_Graph.cpp:21:14: error: 'q' was not declared in this scope 21 | queue q; | ^ BFS_Graph.cpp:31:20: error: 'l' was not declared in this scope 31 | for(T nbr: l[node]){ | ^ Please help me with this errror. list in 9th line of the video is showing error.