void printlevel(struct BT *root) { if(!root) return; struct BT **Q=createQ(); printf("\n\n"); nQ(Q,root); while(root) { root=dQ(Q); printf("[%d]\t",root->data); if(root->l) { nQ(Q,root->l);} if(root->r) nQ(Q,root->r); } printf("\n\n"); }
void bfs(int sr, int sc, int p) { nQ(sr, sc, p); do{ dQ(&r, &c, &p); for(int i=0; i<4; i++) { nr = r + R[i], nc = c + C[i]; if(mat[nr][nc]==1) { if(cost[nr][nc]>cost[r][c]+1) cost[nr][nc]=cost[r][c]+1, nQ(nr, nc, p); } } } while (rear!=front); leaf = p; }