Click here to Skip to main content
16,004,778 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
iam trying to apply bfs in a 2d grid but it's showing errors like:

error:variable or field 'bfs' declared void
error:missing template argument before 'a'

What I have tried:

C++
#include <iostream>
#include
using namespace std;


vector<int> g[100];
int vis[100][100];
int dis[100][100];
int grid[100][100];
int fx[]={1,-1,0,0};
int fy[]={0,0,-1,1};

void bfs(pair a, pair b)
{
    pair x=a;
    memset(vis,0,sizeof vis);
    vis[x.first][x.second]=1;
    dis[x.first][x.second]=0;
    queue<pair>q;
    q.push(x);
    while(!q.empty())
    {
        pair v=q.front();
        for(int i=0;i<4;i++)
        {
            int c=v.first+fx[i];
            int d=v.second+fy[i];
            if(c>-1 and c<r and="" d="">-1 and d<c and="" mode="hold" />            {
                dis[c][d]=dis[v.first][v.second]+1;
                vis[c][d]=1;
                pair y=make_pair(c,d);
                q.push(y);
            }
        }
        q.pop();
    }
    cout<<dis[b.first][b.second]<<endl;

}


int main()
{

    // freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    while(cin>>r>>c)
    {
        if(r!=0&&c!=0)
        {
            memset(grid,0,sizeof grid);
            int n;
            cin>>n;
            int row,number,col;
            for(int i=0; i<n;>            {
                cin>>row>>number;
                for(int j=0; j<number;>                {
                    cin>>col;
                    grid[row][b]=1;

                }
            }
            pair start,stop;
            cin>>start.first>>start.second;
            cin>>stop.first>>stop.second;
            bfs(start,stop);


        }
        else
            break;

    }


    //cout << "Hello world!" << endl;
    return 0;
}
Posted
Updated 26-Jun-16 21:11pm
v2

1 solution

The pair Structure[^] is a template so it needs the item types to be declared, as shown in the example code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900