Hi, i am making a program which will create grid through linked list.I had took four pointers up,down,left,right,and a data part.Through these pointers we will link the nodes eg:
for row 1 the col1 right pointer will point to the right node or col 2 node and the col2 node will point col1 node on the left and so on until the loop for col will break and the roww would be incremneted and row wil become row 2 so for row 2 col 1we will do the same above but with some additional linking eg
row 2 node 1 of col 1 will point through up pointer to the row 1 col1 node 1 and the row node 1 of col 1 will point to row 2 node 1 of col 1 through down pointer and son on until both row and col loop break.
And with these steps we will be able to create a grid of NxN .....
The code is given Below:
if u guys find any problems regarding to my coding please tell me.......
///////////////////creating a grid through linked list////////////////////
else//when row would be greater than than 1 eg: when row is 2 then create 10 column to right
//this process will be done until the rows are not 10 too means loops break
//the problem is in this part of the program because it is not creating proper links with nodes
{
grid *temp1=new grid();
temp1=head;
if(head->getdown()==NULL)//for creating row 2 which will create node under the first node of first column
{
thnx buddy ill remember that but u couldve gave me some proper solution of my problem......
u guys are the experts here and i am just a beginer so plsssss give me some solid solutions i will really appericiate ur help guys.......
1: Make sure that your code is in a format that helps , people to understand it, using the correct code structure and of course posting using the code format on the forums. It helps us a lot and it reduced the time i takes to understand the code, when we do, we will give you an answer.
2: In general with working with a lot of pointers. Try drawing a picture of the pointers. Make sure that your algorithms works as intended.
3: State your problem correctly. Do not just post and say.. what's wrong. Post code, post compile errors, runt-time errors, test cases and such.
Your problem using pointer like this is difficult. I think you should look at how a linked list works and maybe build on of your own. Use that to expand it to a grid. I see that you do a lot of "new" in your code but no "delete". This will cause a memory leak. When you use new in your class you have to, most of the time change your destructor, assignment operator and copy-constructor, The rule of three. Otherwise it will be a big risk that your program has memory leaks. If you don't know that the rule of three is. Please check it up because it's important if not one of the most important things to know when programming c++.