- 论坛徽章:
- 0
|
本帖最后由 presidentccj 于 2010-03-14 23:28 编辑
maze.cpp: In function `int mazepath(int (*)[10], item*, int, int)':
maze.cpp:82: error: expected primary-expression before '{' token
maze.cpp:82: error: expected `;' before '{' token- #include<iostream>
- using namespace std;
- #define m 6 //迷宫的实际行
- #define n 8 //迷宫的实际列
- typedef struct
- {int x,y,d; //横纵坐标及方向
- }DataType ;
- class SeqStack{
- private:
- DataType *base; //栈底指针
- DataType *top; //栈顶指针始终指向栈顶元素的后一个位置
- int size; //栈的大小
- public:
- SeqStack(int stacksize=100){ base=new DataType [stacksize];
- top=base;
- size=stacksize;
- }; //构造了一个空栈,默认大小为100个单元
- ~SeqStack(){ delete[] base;
- }; //销毁一个已存在的栈
- int Empty_Stack(); //判断栈是否为空
- int Push_Stack(DataType e); //将元素e插入到栈顶
- int Pop_Stack(DataType &e); //从栈顶删除一个元素到e中返回
- int GetTop_Stack(DataType &e); //从栈顶取出一个元素到e中返回
- };
- int SeqStack::Empty_Stack() //判断栈是否为空
- {
- return ((top<=base));
- }
- int SeqStack::Push_Stack(DataType e) //进栈操作
- { if(top-base<size)
- { *top=e;
- top++;
- return 1;
- }
- else
- return 0;
- }
- int SeqStack::Pop_Stack(DataType &e) //出栈操作
- { if(top>base)
- { top--;
- e=*top;
- return 1;
- }
- else
- return 0;
- }
- int SeqStack::GetTop_Stack(DataType &e) //取栈顶元素操作
- { if(top>base)
- { e=*(top-1);
- return 1;
- }
- else
- return 0;
- }
- typedef struct
- { int x,y;
- } item ;
- item move[4];
- int mazepath(int maze[m+2 ][n+2 ],item *move,int x0,int y0)
- { //求迷宫路径,入口参数:指向迷宫数组的指针,指向移动方向的指针,
- //开始点(x0,y0),到达点(m,n),返回值:1表示求出路径,0表示无路径
- SeqStack S ;
- DataType temp ;
- int x, y, d, i, j ;
- temp.x=x0 ; temp.y=y0 ; temp.d=-1 ;
- S.Push_Stack(temp) ;
- while (!S.Empty_Stack() )
- { S.Pop_Stack(temp) ;
- x=temp.x ; y=temp.y ; d=temp.d+1 ; maze[x][y]=0;
- while (d<4)
- { i=x+move[d].x ; j=y+move[d].y ;
- if (maze[i][j]==0)
- { temp={x, y, d};
- S.Push_Stack(temp) ;
- x=i ; y=j ; maze[x][y]= -1 ;
- if (x==m&&y ==n) //迷宫有路
- { while (!S.Empty_Stack() )
- { S.Pop_Stack(temp);
- cout<<temp.x<<temp.y ;
- }
- return 1 ;
- }
- else d=0 ;
- }
- else d++ ;
- } //while (d<4)
- } //while
- return 0 ;//迷宫无路
- }
- int main()
- {
- int mazepath(int maze[m+2 ][n+2 ],item *move,int x0,int y0);
- return 0;
- }
复制代码 |
|