| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1530 人关注过本帖
标题:帮忙修改一下程序
只看楼主 加入收藏
crazymanyang
Rank: 1
来 自:湖南岳阳
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-1-7
收藏
 问题点数:0 回复次数:1 
帮忙修改一下程序
#include<iostream.h>   
  #include<stdlib.h>   
   #define null NULL
  struct   node                                                                           //定义了一个结构体,用来记录横纵坐标信息与已经走过的相临的格子   
  {   
          int   x;   
  int   y;   
  node   *next;   
  };   
   
   
  int   chessboard[8][8];                                                         //棋盘,用来记录总的情况   
  int   counter=1;                                                                       //用来记录路线数   
   
  class   stack                                                                             //一个堆栈的类   
  {   
  private:   
  int   flag;   
  node   *array[65];   
  public:   
  void   makenull()   
  {   
  flag=0;   
  }   
   
  bool   isempty()   
  {   
  if(flag)   return   0;   
  else   return   1;   
  }   
   
  bool   isfull()   
  {   
  if(flag==64)   return   1;   
  else   return   0;   
  }   
   
  void   push(node   *a   )   
  {   
  if(!isfull())   
  {   
  array[++flag]=a;   
  chessboard[a->x][a->y]=flag;   
  }   
  }   
   
  void   pop()   
  {   
  if(!isempty())   
  {   
  node   *temp,*temp2;   
  temp=array[flag];   
  chessboard[temp->x][temp->y]=0;   
  while(temp!=null)   {   
  temp2=temp->next;   
  free(temp);   
  temp=temp2;   
  }   
  flag--;   
  }   
  }   
   
  node   *top()   
  {   
  if(!isempty())   
  {   
  return   array[flag];   
  }   
  }   
  };     
   
  bool   compare(node   *a,   node   *b);                                             //比较是否已经走过   
  void   add(node   *a,int   m,int   n);                                               //将选择的路线记录下来,以免重复   
  void   show_routes();                                                                     //打印结果   
   
  void   main()   
  {   
  stack   s;                                                                                   //定义了一个栈   
  s.makenull();                                                                         //初始化栈   
  int   abscissa=0;                                                                     //马的开始的横坐标   
  int   ordinate=0;                                                                     //马的开始的纵坐标   
  node   *first;                                                                           //记录马的初始位置   
  node   *temp;   //备用的空指针   
  node   *a;   
   
  for(int   i=0;   i<8;   i++)                                                       //初始化棋盘   
  for(int   j=0;   j<8;   j++)   
  chessboard[i][j]=0;   
   
  cout<<"please   input   the   original   location   of   the   horse   in   the   chessboard   :"<<endl;   
  cout<<"please   input   the   x   :   ";   
  cin>>abscissa;   
  cout<<endl<<"please   input   the   y   :   ";                         //输入初始位置   
  cin>>ordinate;   
  cout<<endl;   
  chessboard[abscissa][ordinate]=1;   
   
  first=new   node;   
  first->x=abscissa;   
  first->y=ordinate;   
  first->next=null;   
  s.push(first);   
   
  while(!s.isempty())                                                                     
  {   
  a=s.top();   
  temp=new   node;   
  int   m=a->x;                                                                           
          int   n=a->y;   
  int   measure=0;   
   
   
          if(((m-2)>=0)&&((n-1)>=0))   {                                               
  temp->x=m-2;   
          temp->y=n-1;   
          temp->next=null;   
  if(compare(a,temp)&&(chessboard[temp->x][temp->y]==0))   {   
  m=-100;   
  n=-100;   
  measure=1;   
  }   
  }   
   
                  if(((m-2)>=0)&&((n+1)>=0)&&((n+1)<8))   {   
          temp->x=m-2;   
          temp->y=n+1;   
          temp->next=null;   
          if(compare(a,temp)&&(chessboard[temp->x][temp->y]==0))     {   
  m=-100;   
  n=-100;   
  measure=1;   
  }   
  }   
   
                  if(((m-1)>=0)&&((n-2)>=0))   {   
          temp->x=m-1;   
          temp->y=n-2;   
          temp->next=null;   
          if(compare(a,temp)&&(chessboard[temp->x][temp->y]==0)) {   
  m=-100;   
  n=-100;   
  measure=1;   
  }   
  }   
   
                  if(((m-1)>=0)&&((n+2)>=0)&&((n+2)<8))   {   
          temp->x=m-1;   
          temp->y=n+2;   
          temp->next=null;   
          if(compare(a,temp)&&(chessboard[temp->x][temp->y]==0)) {   
  m=-100;   
  n=-100;   
  measure=1;   
  }   
  }   
   
                  if(((m+1)>=0)&&((m+1)<8)&&((n-2)>=0))   {   
          temp->x=m+1;   
          temp->y=n-2;   
          temp->next=null;   
          if(compare(a,temp)&&(chessboard[temp->x][temp->y]==0)){   
  m=-100;   
  n=-100;   
  measure=1;   
  }   
  }   
   
                  if(((m+1)>=0)&&((n+2)>=0)&&((m+1)<8)&&((n+2)<8))   {   
          temp->x=m+1;   
          temp->y=n+2;   
            temp->next=null;   
          if(compare(a,temp)&&(chessboard[temp->x][temp->y]==0)){   
  m=-100;   
  n=-100;   
  measure=1;   
  }   
  }   
   
                  if(((m+2)>=0)&&((n-1)>=0)&&((m+2)<8))   {   
          temp->x=m+2;   
          temp->y=n-1;   
          temp->next=null;   
          if(compare(a,temp)&&(chessboard[temp->x][temp->y]==0)) {   
  m=-100;   
  n=-100;   
  measure=1;   
  }   
  }   
   
                  if(((m+2)>=0)&&((n+1)>=0)&&((m+2)<8)&&((n+1)<8))   {   
            temp->x=m+2;   
          temp->y=n+1;   
          temp->next=null;   
          if(compare(a,temp)&&(chessboard[temp->x][temp->y]==0)) {   
  m=-100;   
  n=-100;   
  measure=1;   
  }   
  }                                   
   
  if(measure==1)   
  {   
  add(s.top(),temp->x,temp->y);   
  s.push(temp);   
  }   
  else   {   
  if(s.isfull())   show_routes();     
  free(temp);   
  s.pop();   
  }   
   
   
  }   
  free(first);                                                                               //释放指针   
  free(temp);   
  cin>>ordinate;                                                                             
  }   
   
   
   
   
   
   
  bool   compare(node   *a,   node   *b)                           //查看该路线是否以已经走过   
  {   
  node   *temp;   
  temp=a->next;   
  while(temp!=null)   {   
  if((temp->x==b->x)&&(temp->y==b->y))   return   0;   
          temp=temp->next;   
  }   
  return   1;   
  }   
   
  void   add(node   *a,int   m,int   n)                                         //记录下某一个动作已经走过   
  {   
  node   *temp;   
  temp=new   node;   
  temp->x=m;   
  temp->y=n;   
  temp->next=null;   
  while(a->next!=null)   a=a->next;   
  a->next=temp;   
  }   
   
  void   show_routes()   
  {   
  cout<<endl<<endl;   
  cout<<"第   "<<counter++<<"   条路线:   "<<endl;   
  for(int   i=0;i<8;i++)   
  {   
  cout<<endl;   
  for(int   j=0;j<8;j++)   
  cout<<chessboard[i][j]<<"     ";   
  }   
   

  错误原因
h:\马踏棋盘\1.cpp(54) : error C2065: 'null' : undeclared identifier
h:\马踏棋盘\1.cpp(54) : error C2446: '!=' : no conversion from 'int' to 'struct node *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
h:\马踏棋盘\1.cpp(54) : error C2040: '!=' : 'struct node *' differs in levels of indirection from 'int'
h:\马踏棋盘\1.cpp(101) : error C2440: '=' : cannot convert from 'int' to 'struct node *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
h:\马踏棋盘\1.cpp(116) : error C2440: '=' : cannot convert from 'int' to 'struct node *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
h:\马踏棋盘\1.cpp(127) : error C2440: '=' : cannot convert from 'int' to 'struct node *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
h:\马踏棋盘\1.cpp(138) : error C2440: '=' : cannot convert from 'int' to 'struct node *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
h:\马踏棋盘\1.cpp(149) : error C2440: '=' : cannot convert from 'int' to 'struct node *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
h:\马踏棋盘\1.cpp(160) : error C2440: '=' : cannot convert from 'int' to 'struct node *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
h:\马踏棋盘\1.cpp(171) : error C2440: '=' : cannot convert from 'int' to 'struct node *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
h:\马踏棋盘\1.cpp(182) : error C2440: '=' : cannot convert from 'int' to 'struct node *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
h:\马踏棋盘\1.cpp(193) : error C2440: '=' : cannot convert from 'int' to 'struct node *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
h:\马踏棋盘\1.cpp(228) : error C2446: '!=' : no conversion from 'int' to 'struct node *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
h:\马踏棋盘\1.cpp(228) : error C2040: '!=' : 'struct node *' differs in levels of indirection from 'int'
h:\马踏棋盘\1.cpp(241) : error C2440: '=' : cannot convert from 'int' to 'struct node *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
h:\马踏棋盘\1.cpp(242) : error C2446: '!=' : no conversion from 'int' to 'struct node *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
h:\马踏棋盘\1.cpp(242) : error C2040: '!=' : 'struct node *' differs in levels of indirection from 'int'
h:\马踏棋盘\1.cpp(256) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

马踏棋盘.exe - 18 error(s), 0 warning(s)
搜索更多相关主题的帖子: 结构体 null 
2008-01-07 18:49
fbird
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2006-8-11
收藏
得分:0 
我这里运行没有问题啊,都可以正常运行~~建议用list做容器,操作起来都比较方便~~
2008-01-07 19:45
快速回复:帮忙修改一下程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019966 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved