I have the following code in C
, for a search in width:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
//Variáveis globais
int id = 0;
int proximo = 0;
//Função de Busca em Largura
int buscaLargura(int *grafo, int alvo, int inicio, int tamanho)
{
struct str_no fila[tamanho];
int indice = 0;
int achou = 0;
//Procura nó inicial
while(achou == 0)
{
if(grafo->id == inicio)
{
achou = 1;
}
else
{
grafo = grafo->proximo;
}
}
achou = 0;
}
//Procura o nó alvo
fila[indice] = grafo;
indice++;
while(indice > 0 && achou == 0)
{
if(grafo->id == alvo)
{
achou = 1;
}
else
{
while(grafo->proximo != NULL)
{
grafo = grafo->proximo;
fila[indice] = grafo;
indice++;
}
//Desenfileira
grafo = pilha[0];
for(int i = 1; i < indice; i++)
{
pilha[i-1] = pilha[i];
}
indice--;
}
return(grafo);
}
Whenever I try to run, the "CodeBlocks" compiler returns the following ERROR :
|| === Build file: "no target" in "no project" (compiler: unknown) === | In function 'searchlight': | | 17 | error: array type has incomplete element type | | 24 | error: request for member 'id' in something not a structure or union | | 30 | error: request for member 'proximo' in something not a structure or union | error: 'index' undeclared here (not in a function) | | 37 | warning: data definition has no type or storage class | | 37 | error: 'graph' undeclared here (not in a function) | | 38 | error: expected '=', ',', ';', 'asm' or ' attribute ' before '++' token | | 39 | error: expected identifier or '(' before 'while' | || === Build failed: 7 error (s), 1 warning (s) (0 minute (s), 0 second (s)) === |