• Source
    1. cout<<"Enter limit: ";
    2. cin>>lim;
    3. dls(strt,lim);
    4.  
    5. void dls(int node, int lim)
    6. {
    7. dls_level++; ///If function enters in a new/child node level incriments.
    8.  
    9. ///This segment works to return if goal acheived. (Main modification of Standerd algo).
    10. if(get_goal) return;
    11. if(node==goal)
    12. {
    13. path.push_back(node);
    14. get_goal=true;
    15. return;
    16. }
    17.  
    18. path.push_back(node);
    19. vis[node]=1;
    20. for(int i=1;i<=n;i++)
    21. {
    22. if(graph[node][i] && !vis[i])
    23. {
    24. if(dls_level<lim) dls(i,lim);
    25. }
    26. }
    27.  
    28. dls_level--; ///If Function returns from a node, level decrements.
    29. }