i want to do topo sort but i want to output the lexographically smallest topo sort vesion of that. http://www.spoj.com/problems/TOPOSORT/ here goes the link of problem. actually, i have done this using DFS , but i am able to do the question "print any possible topo sort" of the graph. thanks if u can help me.

void dfs(int p)
{
      if(used[p]==1)
      {
                  flag=false;
                  return;  
      }
      else if(used[p]==0)
      {
             used[p]=1;

             for(int i=0;i<g[p].size();i++)
             {
                  dfs(g[p][i]);
             }

             used[p]=2;

             ans.push_back(p);
      }
      else
      return;
}

here ans vector is the answer in which topo sort is there. thanks if u can help me .

Why are you so angry I'm just trying to help??

No, you're not. You clearly said you can't help, so how could your post possibly be construed as "trying to help"? Your link is totally irrelevant to the question about topological sorting. Given that your post is both off topic and completely pointless, I can only presume your intention was to boost your post count with meaningless posts.

Why is everyone so angry at me. I know a website that could help him!! So I'm not posting meaningless post!!!!

I know a website that could help him!!

Please point out exactly the page on w3schools that helps him, and explain how it helps.

If the only way you can "help" is by posting general and largely useless links, then you're not helping.

There is a website called http://www.cprogramming.com. This website can help a lot.

I'm very familiar with cprog.com, and I can definitely tell you that the only place you can get help on topological sorting is the forum. However, based on previous questions of that nature, it's not even guaranteed help.

If you want to learn more you can go to http://www.w3schools.com

Please point out exactly the page on w3schools that helps him, and explain how it helps. I know for a fact that w3schools has absolutely nothing relevant to this thread, so it's a completely off-topic and useless link.

Edited 3 Years Ago by deceptikon

IT IS NOT USELESS. What I was saying was use cprogramming.com. But also go on w3schools.com if you want to learn another program. I bet you haven't even gone on w3schools.com. When you do you will see what I was talking about. Also it is not nice to say If you can't help don't say anything! At least helping a little bit is better than saying nothing!!

What I was saying was use cprogramming.com.

Thanks for clarifying the obvious. :rolleyes:

But also go on w3schools.com if you want to learn another program.

How is that relevant to this thread?

I bet you haven't even gone on w3schools.com. When you do you will see what I was talking about.

I've been there. I go there regularly. I'm certain that w3schools will not help nitin1 with the question he asked in this thread. And you've completely failed to specify exactly how you think it will help and included a specific link to the page you think will help rather than the home page.

At least helping a little bit is better than saying nothing!!

When you start helping even a little bit, I'll stop complaining that you're not helping. In fact, I'm almost to the point of treating you as a troll who's intentionally posting off-topic shit to get a rise out of people. People have flagged your posts as such to the moderation team, and I'm starting to agree with that assessment. And if/when I reach that point, I'll start deleting your posts and laying down infractions for Keep It Organized (probably retroactively to clean up the threads you're causing trouble in).

Edited 3 Years Ago by deceptikon

I found 9 errors in this program. I hope this will help.

(In line 5.19) :5:19: error: use of undeclared identifier 'flag'

              flag=false;
              ^

(In line 5.24) :5:24: error: use of undeclared identifier 'false'

              flag=false;
                   ^

(In line 8.15) :8:15: error: use of undeclared identifier 'used'

                else if(used[p]==0)
                ^

(In line 10.14) :10:14: error: use of undeclared identifier 'used'

                 used[p]=1;
                 ^

(In line 11.28) :11:28: error: use of undeclared identifier 'g'

                  for(int i=0;i<g[p].size();i++)
                       ^

(In line 13.23) :13:23: error: use of undeclared identifier 'g'

                    dfs(g[p][i]);
                    ^

(In line 15.14) :15:14: error: use of undeclared identifier 'used'

                  used[p]=2;
                  ^

(In line 16.14) :16:14: error: use of undeclared identifier 'ans'

                  ans.push_back(p);

I found 9 errors in this program. I hope this will help.

That's much better, though still not especially helpful when looking at the OP from a position of understanding. I'll restate my original advice that you should learn before trying to teach. It's obvious that the "program" in the OP is only a snippet, it's not meant to be compilable as-is. As such, there are guaranteed to be compilation problems with unspecified global variables, missing headers, and the lack of a main() function. nitin1 isn't that much of a beginner, so pointing out such errors is unproductive.

Further, judging by the presence of the ans.push_back(p) and g[p].size() expressions, I'd wager that this code is actually C++ and the dfs() function is really a class method. Whether nitin1 wants C or not is a question that he'll have to answer though. I may need to move this thread to the C++ forum.

Edited 3 Years Ago by deceptikon

This article has been dead for over six months. Start a new discussion instead.