²é¿´: 256  |  »Ø¸´: 0
µ±Ç°Ö÷ÌâÒѾ­´æµµ¡£

zhliye

гæ (³õÈëÎÄ̳)

[½»Á÷] ¡¾ÇóÖú¡¿ÇóÖú¸ßÊÖ£¨Ö¸Õ룬ջ£©µÄÎÊÌ⣬Ôõô×ÜÒç³ö°¡£¿£¿£¿

ÓÃջʵÏÖµÄÒ»¸öÃÔ¹¬Ëã·¨£¬µ«ÊÇÖ´Ðгö´í£¬×Ô¼ºÃ»¿´³öÊÇɶÎÊÌ⣬ÔÎÁË£¬Çë´ó¼Ò°ïæָÕý¡£
#include
#include
#include

#define OK 1
#define STACKINITSIZE 100
#define STACKINCREMENT 50
#define OVERFLOW -2
#define ERROR 0
#define TRUE 1
#define FALSE 0
#define MAXSIZE 10

//maze`s MAP ;'O' means can pass and '1' means here is blocked.
int Maze[MAXSIZE][MAXSIZE]={
       {1,1,1,1,1,1,1,1,1,1},
       {1,0,0,1,0,0,0,1,0,1},
       {1,0,0,1,0,0,0,1,0,1},
       {1,0,0,0,0,1,1,0,0,1},
       {1,0,1,1,1,0,0,0,0,1},
       {1,0,0,0,1,0,0,0,0,1},
       {1,0,1,0,0,0,1,0,0,1},
       {1,0,1,1,1,0,1,1,0,1},
       {1,1,0,0,0,0,0,0,0,1},
       {1,1,1,1,1,1,1,1,1,1},
  };

//dirArray ,from east->south->west->north,the coordinate increment
int Dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};

//PosType is way`s coordinate
typedef struct{
   int x;
   int y;
}PosType;

//current position whther can pass
int Pass(PosType curpos){
    if(Maze[curpos.x][curpos.y]==0) return OK;
    return ERROR;
}

//if this position can pass ,footprint
void FootPrint(PosType curpos){
     Maze[curpos.x][curpos.y]=2;
}

//if can't pass ,marking
void MarkPrint(PosType curpos){
     Maze[curpos.x][curpos.y]=4;
}

//seek the next position
PosType NextPos(PosType curpos,int dir){
   curpos.x=curpos.x+Dir[dir][0];
   curpos.y=curpos.y+Dir[dir][1];
   return curpos;
  }

//MazeType is stack`s element type
typedef struct{
int ord;
PosType seat;
int  di;
}MazeType;

//stack node
typedef struct
{
MazeType *base;
MazeType *top;
int stacksize;
}SqStack,*pStack;

//init stack
int InitStack (pStack S)
{
  S->base=(MazeType *)malloc(STACKINITSIZE * sizeof(MazeType));
  if(!S->base) exit(OVERFLOW);
   printf("init is succeed";
  S->stacksize=STACKINITSIZE;
  S->top=S->base;
return OK;
}

//Push Stack
int PushStack(pStack S,MazeType e){
if((S->top-S->base) >= S->stacksize)
    {
     S->base=(MazeType *)realloc(S->base,(S->stacksize+STACKINCREMENT) * sizeof(MazeType));
     if(!S->base) {printf("stack is full and reseting fails";exit(OVERFLOW);}
      S->top=S->base+S->stacksize;
      S->stacksize+=STACKINCREMENT;
    }
    *S->top++=e;
return OK;
}

//pop stack
int PopStack(pStack S,MazeType *q){
if(S->top==S->base) return ERROR;
  *q = *--S->top;
return OK;
}

//judge whther stack is empty
int  EmptyStack(pStack S){
    if(S->top==S->base) return OK;
    return ERROR;
}
//destroy stack
void DestroyStack(pStack S){
   S->top=S->base;
   free(S->base);
}
//above are stack`s base operation

//seek the mazepath
int   Mazepath(pStack S,PosType start,PosType end){
  PosType curpos=start;

  int curstep=1,dir=0;//dir is from 0 to3 coorespodence  east,south,west,north
  MazeType elem,pelem;

do{
     if(Pass(curpos)){
         FootPrint(curpos);
         elem.ord=curstep,elem.seat=curpos,elem.di=dir;
        if(PushStack(S,elem)) printf("push1 is wrong";
     if(curpos.x==end.x&&curpos.y==end.y) return TRUE;
     curpos=NextPos(curpos,elem.di);
     curstep++;
     }//if
    else{
        if(!EmptyStack(S)){
                  if( !PopStack(S,&pelem)) {printf("pop1 stack failing";exit(OVERFLOW);}//PopStack
                    while(!EmptyStack(S)&&pelem.di==3){
                        MarkPrint(pelem.seat);
                      if(!PopStack(S,&pelem)) printf("pop2 wrong";
                     }//while
              if(pelem.di<3){
                   pelem.di++;
                if(!PushStack(S,pelem)) printf("push2 is wrong";
                   curpos=NextPos(pelem.seat,pelem.di);
               }//if
        }//if
     }//else
  }while(!EmptyStack(S));
   return   FALSE;
}


main(){
        PosType  start,end,tests;
           start.x=1,start.y=1,end.x=8,end.y=8;
        SqStack test;
         MazeType elem,element;
         int i,j;
         printf("The Maze is; \n";
        for(i=0;i
          for(j=0;j
                printf("%d  ",Maze[j]);if(j==9) printf("\n";
            }
printf("%d",&test);
        if(Mazepath(&test,start,end)) printf("This maze has no exit!";
       printf("%d",&test);
    while(!EmptyStack(&test)){
           if(!PopStack(&test,&elem)) printf("mappath print fail";
           printf("%d->",elem.ord);
           printf("(%d,%d)->",elem.seat.x,elem.seat.y);
     }//while*/
DestroyStack(&test);
}


´Ë³ÌÐòÔËÐÐ*£¨GCC£©ºó³öÏÖÈçϵĴíÎó£¬Çë¸ßÊÖÖ¸µã

*** glibc detected *** ./a.out: realloc(): invalid pointer: 0xbff98759 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(realloc+0x39c)[0xb7e199ec]
/lib/tls/i686/cmov/libc.so.6(realloc+0x3c)[0xb7e1968c]
./a.out[0x80485f9]
./a.out[0x80487a0]
./a.out[0x80489f1]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe0)[0xb7dc0450]
./a.out[0x8048441]
======= Memory map: ========
08048000-08049000 r-xp 00000000 08:01 461093     /home/lgp/C/a.out
08049000-0804a000 rw-p 00000000 08:01 461093     /home/lgp/C/a.out
0804a000-0806b000 rw-p 0804a000 00:00 0          [heap]
b7da9000-b7daa000 rw-p b7da9000 00:00 0
b7daa000-b7ef3000 r-xp 00000000 08:01 712708     /lib/tls/i686/cmov/libc-2.7.so
b7ef3000-b7ef4000 r--p 00149000 08:01 712708     /lib/tls/i686/cmov/libc-2.7.so
b7ef4000-b7ef6000 rw-p 0014a000 08:01 712708     /lib/tls/i686/cmov/libc-2.7.so
b7ef6000-b7ef9000 rw-p b7ef6000 00:00 0
b7ef9000-b7f03000 r-xp 00000000 08:01 696339     /lib/libgcc_s.so.1
b7f03000-b7f04000 rw-p 0000a000 08:01 696339     /lib/libgcc_s.so.1
b7f04000-b7f07000 rw-p b7f04000 00:00 0
b7f07000-b7f08000 r-xp b7f07000 00:00 0          [vdso]
b7f08000-b7f22000 r-xp 00000000 08:01 696332     /lib/ld-2.7.so
b7f22000-b7f24000 rw-p 00019000 08:01 696332     /lib/ld-2.7.so
bff84000-bff99000 rw-p bffeb000 00:00 0          [stack]
-1074166568Aborted
»Ø¸´´ËÂ¥

» ²ÂÄãϲ»¶

ÎÒÒª³ÔÇà²Ë¡£
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
Ïà¹Ø°æ¿éÌø×ª ÎÒÒª¶©ÔÄÂ¥Ö÷ zhliye µÄÖ÷Ìâ¸üÐÂ
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[¿¼ÑÐ] Ò»Ö¾Ô¸±±¾©»¯¹¤´óѧ 070300 ѧ˶ 336·Ö Çóµ÷¼Á +4 vvÃÔ 2026-03-22 4/200 2026-03-22 23:29 by king123£¡
[¿¼ÑÐ] 352Çóµ÷¼Á +3 ´óÃ×·¹£¡ 2026-03-22 3/150 2026-03-22 23:28 by king123£¡
[¿¼ÑÐ] 277²ÄÁÏ¿ÆÑ§Ó빤³Ì080500Çóµ÷¼Á +7 ×ÔÓɼå±ý¹û×Ó 2026-03-16 7/350 2026-03-22 22:40 by ACS Nano¡ª¡ª
[¿¼ÑÐ] Ò»Ö¾Ô¸Î÷°²½»Í¨´óѧ²ÄÁϹ¤³Ìרҵ 282·ÖÇóµ÷¼Á +11 ·ãÇÅZL 2026-03-18 13/650 2026-03-22 20:26 by edmund7
[¿¼ÑÐ] 298Çóµ÷¼Á +6 Éϰ¶6666@ 2026-03-20 6/300 2026-03-22 20:21 by edmund7
[¿¼ÑÐ] 306Çóµ÷¼Á +6 chuanzhu´¨Öò 2026-03-18 6/300 2026-03-22 19:39 by ¹«èªåÐÒ£
[¿¼ÑÐ] ÉúÎïѧ071000 329·ÖÇóµ÷¼Á +5 ÎÒ°®ÉúÎïÉúÎﰮΠ2026-03-17 5/250 2026-03-22 16:42 by tcx007
[¿¼ÑÐ] 269ר˶Çóµ÷¼Á +6 ½ð¶÷±´ 2026-03-21 6/300 2026-03-22 14:31 by ColorlessPI
[¿¼ÑÐ] 280Çóµ÷¼Á +11 ¹¾ààÏþÏþ 2026-03-18 12/600 2026-03-21 22:40 by ACS Nano¡ª¡ª
[¿¼ÑÐ] ¹¤¿Æ0856Çóµ÷¼Á +3 ãåÎö͡͡ 2026-03-21 3/150 2026-03-21 18:30 by ѧԱ8dgXkO
[¿¼ÑÐ] 346Çóµ÷¼Á[0856] +4 WayneLim327 2026-03-16 7/350 2026-03-21 04:02 by JourneyLucky
[¿¼ÑÐ] 307Çóµ÷¼Á +3 wyyyqx 2026-03-17 3/150 2026-03-21 03:20 by JourneyLucky
[¿¼ÑÐ] 301Çóµ÷¼Á +10 yyÒªÉϰ¶Ñ½ 2026-03-17 10/500 2026-03-21 03:14 by JourneyLucky
[¿¼ÑÐ] 304Çóµ÷¼Á +6 ÂüÊâ2266 2026-03-18 6/300 2026-03-21 00:32 by JourneyLucky
[¿¼ÑÐ] 085600²ÄÁÏÓ뻯¹¤ +8 °²È«Éϰ¶£¡ 2026-03-16 8/400 2026-03-20 22:13 by luoyongfeng
[¿¼ÑÐ] 081700»¯¹¤Ñ§Ë¶µ÷¼Á +3 ¡¾1¡¿ 2026-03-16 3/150 2026-03-19 23:40 by edmund7
[¿¼ÑÐ] ÉúÎïѧµ÷¼ÁÕÐÈË£¡£¡£¡ +3 ɽº£Ììá° 2026-03-17 4/200 2026-03-19 21:34 by ÔõôÊÍ»³
[¿¼ÑÐ] 344Çóµ÷¼Á +6 knight344 2026-03-16 7/350 2026-03-18 20:13 by walc
[¿¼ÑÐ] ²ÄÁÏ£¬·ÄÖ¯£¬ÉúÎ0856¡¢0710£©£¬»¯Ñ§ÕÐÉúÀ² +3 Eember. 2026-03-17 9/450 2026-03-18 10:28 by Eember.
[¿¼ÑÐ] 283Çóµ÷¼Á +3 Ìý·ç¾ÍÊÇÓꣻ 2026-03-16 3/150 2026-03-17 07:41 by ÈÈÇéɳĮ
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û