home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.disi.unige.it
/
2015-02-11.ftp.disi.unige.it.tar
/
ftp.disi.unige.it
/
pub
/
.person
/
CataniaB
/
teach-act
/
esempi
/
Comp-Sep
/
lab.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-04-19
|
1KB
|
49 lines
#include <stdio.h>
#include "stack.h"
#include "input.h"
stack S; /* utilizzo pop, push, is_empty_stack, print_stack */
extern int laby[DIM][DIM]; /* definita in input,h */
int move(int i,int j,int *newi,int *newj)
/* muove i e j alla prox. casella libera (newi,newj)
fallisce se non ci sono caselle libere */
{
if (j+1<DIM && laby[i][j+1]) {*newj=j+1; return 1;}
else if (i+1<DIM && laby[i+1][j]) {*newi=i+1; return 1;}
else if (i>0 && laby[i-1][j]) {*newi=i-1; return 1;}
else if (j>0 && laby[i][j-1]) {*newj=j-1; return 1;}
return 0;
}
main()
{
int i,j,continua;
init_stack(&S);
continua=true;
i=InX;
j=InY;
while (continua)
{
if ( i==OutX && j==OutY ) break;
if (laby[i][j])
{
laby[i][j]=0;
push(i,j,&S);
print_stack(&S);
}
if (!move(i,j,&i,&j)) /* move ha side effect su i e j */
if (continua=is_empty_stack(&S))
{
pop(&S);
top(&i,&j,&S);
}
}
if (i==OutX && j==OutY) print_stack(&S);
else printf("\n No way out!\n");
}