• Source
    1. while(!get_goal)
    2. {
    3. memset(vis,0,sizeof(vis));
    4. path.clear();
    5. ids(strt,lim++);
    6. }
    7.  
    8. void ids(int node, int lim)
    9. {
    10. dls_level++;
    11.  
    12. ///This segment works to return if goal acheived. (Main modification of Standerd algo).
    13. if(get_goal) return;
    14. if(node==goal)
    15. {
    16. path.push_back(node);
    17. get_goal=true;
    18. return;
    19. }
    20.  
    21. path.push_back(node);
    22. vis[node]=1;
    23. for(int i=1;i<=n;i++)
    24. {
    25. if(graph[node][i] && !vis[i])
    26. {
    27. if(dls_level<lim) ids(i,lim);
    28. }
    29. }
    30. dls_level--;
    31. }