急求  很急  迷宫问题c程序
[迷宫问题]在迷宫中求从入口到出口的一条简单路径。迷宫可用下图中所示的方块来表示,每个方块或者是通道(用空白方块表示)或者是墻(用带阴影的方块表示)。
我给你找了个,你看看行不,不是我写的.

#include"stdio.h"
#include"malloc.h"
#include"stdlib.h"
typedef struct 
{
 int  x,y;
 int  ord;
 int  der;
 
}ElemType;
typedef struct 
{
 ElemType *base;
 ElemType *top;
 int  stacksize;
}Sqstack;
void  InitStack(Sqstack &S);
void  Push(Sqstack &S, ElemType e);
int   Pop(Sqstack &S,ElemType &e);
void  NextPos(int *x, int *y, int der);
void InitStack(Sqstack &S)
{
 S.base=(ElemType*)malloc(sizeof(ElemType)*INIT_SIZE);
 if(!S.base) exit(1);
 S.top=S.base;
 S.stacksize=INIT_SIZE;
}
void Push(Sqstack &S, ElemType e)
{
 if(S.top-S.base==S.stacksize) 
 {
  S.base=(ElemType*)malloc(sizeof(ElemType)*(INIT_SIZE+INCREMENT));
  S.top=S.base+S.stacksize;
  S.stacksize+=INCREMENT;  
 }
 
 *(S.top++)=e;
}
int  Pop(Sqstack &S,ElemType &e)
{
 if(S.top==S.base) return 0;
 e=*(--S.top);
 
 return 1;
}
void NextPos(int *x, int *y, int der)
{ 
 switch(der)
 {
  case 1:
    ++(*x);
    break;
  case 2:
    ++(*y);
    break;
  case 3:
    --(*x);
    break;
  case 4:
    --(*y);
    break;
  default:
    break;
 }
}
int main()
{
 Sqstack S;
 int x,y,step;
 
 ElemType e,*P;
 char maze[10][10]=
 {
  {'#',' ','#','#','#','#','#','#','#','#'},
  {'#',' ',' ','#',' ',' ',' ','#',' ','#'},
  {'#',' ',' ','#',' ',' ',' ','#',' ','#'},
  {'#',' ',' ',' ',' ','#','#',' ',' ','#'},
  {'#',' ','#','#','#',' ',' ',' ',' ','#'},
  {'#',' ',' ',' ','#',' ',' ',' ',' ','#'},
  {'#',' ','#',' ',' ',' ','#',' ',' ','#'},
  {'#',' ','#','#','#',' ','#','#',' ','#'},
  {'#','#',' ',' ',' ',' ',' ',' ',' ','#'},
  {'#','#','#','#','#','#','#','#',' ','#'},
 };
 
 printf("The needed found maze are as follows:\n\n");
 for(x=0;x<10;x++)
 {
  for(y=0;y<10;y++)
   printf("%c",maze[x][y]);
  printf("\n");
 }
 
 InitStack(S);
 P=S.base;
 x=0; y=1;
 step=1;
 do
 {
   if(maze[x][y]==' ')
   { 
    maze[x][y]='1'; 
    e.x=x;
    e.y=y;
    e.ord=step;
    e.der=1;
    Push(S,e);
    if(x==9&&y==8)  break;
    NextPos(&x,&y,1);
    step++;
   
   }
   else
   {
     if(S.base!=S.top)
     {
       Pop(S,e);
       while(e.der==4)
       {
        maze[e.x][e.y]='@';
        Pop(S, e);
       }
     }
     if(e.der<4)
     {
      e.der++;
      Push(S, e);
      x=e.x;
      y=e.y;
      NextPos(&x, &y, e.der);
     }
   }    
     
  
 
 } while(S.top!=S.base);
 printf("\n找到路径: 用1表示走的路,@表走的死路,#表墙: \n\n");
 for(x=0;x<10;x++)
 { for(y=0;y<10;y++)
   printf("%c",maze[x][y]);
  printf("\n");
 }
 printf("坐标表示如下:\n\n");
 while(S.base!=S.top)
 {
  if(P==S.base)
  {
   printf("(%d,%d)", (*S.base).x, (*S.base).y);
   S.base++;
  }
  else 
  {
   printf(" -> (%d,%d)", (*S.base).x, (*S.base).y);
   S.base++;
  }
 
 }
 printf("\n");
 free(P);
 return 0;
}
