Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6757085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:36:15+00:00 2026-05-26T13:36:15+00:00

i have seen in internet following DFS algorithm #include<iostream> #include<queue> #define MAX 100 using

  • 0

i have seen in internet following DFS algorithm

#include<iostream>
#include<queue>
#define MAX 100

using namespace std;

queue<int> myQueue;
int G[MAX][MAX];
int visit[MAX];
int V, E;


void dfs(int s) {
     int i, j, node;
     memset(visit, 0, sizeof(visit));
     myQueue.push(s);

     while(!myQueue.empty())
     {
          node = myQueue.front();
          myQueue.pop();
          if(visit[node]) continue;
          visit[node] = 1;
          cout << node << " ";

          for(i=0; i<V; i++)
               if(G[i][node]) myQueue.push(i);
          for(j=0; j<V; j++)
               if(G[node][j]) myQueue.push(j);     
     }

}

int main() {
    memset(visit, 0, sizeof(visit));
    dfs(0);
    return 0;
}

my question is that it uses queue instead of stack, so is it correct?also when i should enter graph,should it be like adjacent matrix or?please help me,this algorithm uses default values,so how can i change it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:36:15+00:00Added an answer on May 26, 2026 at 1:36 pm

    Interesting. I found the code you are referring to http://www.koders.com/cpp/fid1107E4F79ED191B482853E3206A2F13FC77B4310.aspx.

    Sure enough that uses the queue class from the Standard C++ Library and, as such, implements a breadth-first search algorithm. Using a C++ stack should give you the depth-first search you desire.

    Goes to show you can’t trust everything you see on the Internet (perhaps even including this answer). 🙂

    As to your second question, this posted code is indeed using an adjacency matrix. In fact, you can even be more precise and say, by inspecting the code, that it is implementing a undirected graph without parallel edges.

    ADDENDUM

    The code in action, showing it is a BFS: http://ideone.com/mLl23

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen posts all over the internet that talk about how to fix
I've seen a few fixes for allowing PNG images to have transparency in Internet
I have seen tutorials on the internet for making multithreaded applications in C++ on
I have seen this question floating around the internet, but I haven't found a
I have seen many apps that load data to UITableViews from the internet, and
As I have seen, SQL 2008 no longer offers replication over internet in very
I have seen partial solutions over the internet but none that really satisfied me:
I have seen on internet to run command like mvn . . . .
I have seen this question asked all over the internet and answered in many
I have seen WiX and iis (cannot connect to internet information server) This question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.