Problem in making my grid

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:-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#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();


}




Last edited on
main must return int.
The Console is a Terrible Medium for Games http://www.cplusplus.com/forum/articles/28558/

I didn't check your implementation of gridlist (because of the lack of indentation).
methods to traverse your grid:
* LRUB: start at upper left.
_store the down pointer.
_go to the right all you can.
_go to the stored down.
_Repeat

* Snake: start at upper left.
_go to the right all you can
_go down
_go left all you can
_go down
_Repeat

* Flood fill: start at any node
_If the node was already visited, end.
_Visit the node
_Flood fill its neighbours.
Topic archived. No new replies allowed.