#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(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)