/* * Funcao que remove o ultimo frame da pilha, liberando o espaco * */ void dropFrame(){ unsigned int *local; struct snode * p; if(topo==NULL) erroFatal("Stack is empty"); while(topo!=NULL&&topo!=base){ pop(); } checa(topo); p = topo->prox; unsigned int valor = topo->valor; //free(topo); topo=p; checa(topo); local=(unsigned int *)valor; //free(local); p = topo->prox; valor = topo->valor; //free(topo); topo=p; base=(struct snode *)valor; //printf("local=0x%X\n",(unsigned int)local); //printf("base=0x%X\n",(unsigned int)base); }
int main() { while(1) { scanf("%d", &n); if(!n) break; for(int i=0; i<n; i++) { scanf("%s", matriz[i]); } int cont = 0; memset(visi, false, sizeof(visi)); for(int i=0; i<n; i++) if(!visi[i]) { cont++; for(int j=0; j<n; j++) if(matriz[i][j] == '1') { if(!checa(j, i)) { cont = -1; } visi[j] = true; } visi[i] = true; if(cont == -1) break; } if(cont == -1) { printf("impossivel\n"); } else { printf("%d\n", cont); } } }
void push(unsigned int valor, char tipo){ struct snode *novo = calloc(1,sizeof(struct snode)); checa(novo); novo->valor=valor; novo->tipo=tipo; novo->prox=topo; topo=novo; }
void newFrame(unsigned int lv_size){ unsigned int * local = calloc(lv_size+1, sizeof(unsigned int)); checa(local); local[0]=lv_size; push((unsigned int) base,0); push((unsigned int) local,0); //printf("local=0x%X\n",(unsigned int)local); //printf("base=0x%X\n",(unsigned int)base); base=topo; }
void setLocalVar(int index, int value){ if(base==NULL){ erroFatal("Stack frame is empty"); } unsigned int * local = (unsigned int *) base->valor; checa(local); if(index<0 || index >= local[0]){ erroFatal("Access out of bounds"); } local[index+1]=value; }