我的网格程序有问题 [英] Having problem in my grid program

查看:80
本文介绍了我的网格程序有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些如何使用c ++中的链表而不是输入数据来制作网格的方法,只是增加大小来知道是否已创建节点,但是我不知道是否实际创建了网格,因为我不知道如何显示网格有人可以告诉我一种显示网格的方法吗,所以我应该知道我的网格是否正确.还请告诉我是否有错误,我也想知道如何在网格中移动星星并输出它在屏幕上,即用户将其移动
请运行并检查它.谢谢
以下是我的代码:-

Hi i have have some how made a grid using linked list in c++ instead of input data iam just incrementing size to know whether nodes are made or not but i dont know whether actually grid is made or not because i dont know how to display a grid can anyone tell me a method to display my grid so i should know whether my grid is as it should be.Please also tell if there is mistake and i also want to know how to move a star in my grid and output it on screen i.e user will move it
please run and check it. Thanks
below is my code:-

#include<iostream.h>
//the grid that i have made is of 2 rows and 4 columns
class grid // grid class
{

private:
int size;
grid *east;//this pointer acting as next pointer or right pointer
grid *west;//this pointer acting as previous pointer or left pointer
grid *north;//this pointer acting as up pointer
grid *south;//this pointer acting as down pointer
public:
grid()
{
size=0;
east=west=north=south=NULL;

}
grid(int s)
{
size=s;
east=west=north=south=NULL;




}
void setsize(int s)
{

size=s;
}
int getsize()
{

return size;

}
void setwest(grid *w)
{

west=w;
}
grid *getwest()
{

return west;

}

void seteast(grid *e)
{

east=e;
}
grid *geteast()
{

return east;

}

void setnorth(grid *n)
{

north=n;
}
grid *getnorth()
{

return north;

}




void setsouth(grid *s)
{

south=s;
}
grid *getsouth()
{

return south;

}






};
class gridlist //grid list class

{
private:
grid *head;
grid *current;
grid *lastcurrent;
public:

gridlist()
{

head=NULL;
current=NULL;
lastcurrent=NULL;



}
void create()// creating grid
{grid *temp=new grid();
int i=1;
for(int row=1;row<=2;row++)//loop for row the grid is 2 x 4 2 rows and 4 columns
{
for(int col=1;col<=4;col++)// column loop
{

if(head==NULL)
{
temp->setsize(i);
head=current=lastcurrent=temp;
cout<<current->getsize()<<endl;
}
else if(i<=4)
{
temp->setsize(i);
lastcurrent=current;
current->seteast(temp);
current=temp;
current->setwest(lastcurrent);


current->seteast(NULL);
cout<<current->getsize()<<endl;
}
if(i>4)// problem here after the fourth node
{/*i have confusion whether after the 4th node the fifth node is connecting with first node or not. 4th node should not have connection
with 5th node i.e 4th node should point to null which is done above similarly 6th node should have connection with node 2 and 5 and so on
this is why i need to make display function to confirm that please help*/
grid *temp1=new grid();
grid * temp3= new grid();
temp1=head;
temp3=head;
current=head;
lastcurrent=head;

temp->setsize(i);
temp3->setsouth(current);
temp3->setnorth(temp);
/*while(temp1->getwest()!=head)
{
lastcurrent=lastcurrent->getwest();
temp1->setsouth(current);
temp1->setsize(i);
}*/

cout<<current->getsize()<<endl;

}

i++;
}

}

}



};
void main()
{

gridlist l;
l.create();


}

推荐答案

我建​​议您使用调试器检查变量.调试器将是您最好的朋友.您越早学习如何使用它,您的工作效率就会越高.设置一个断点,逐步执行代码,您将看到变量如何变化,并检测无效状态的原因.
I would suggest you use a debugger to inspect your variables. The debugger will be your best friend. The earlier you learn how to use it, the more productive you will become. Set a breakpoint, step through your code, and you will see how variables changes, and detect reasons for invalid states.


这篇关于我的网格程序有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆