Ok i am writing a program to manipulate structures that are similar to linked list. I have a file that has these contents.
4 5
0 0 0
0 1 0.1
0 2 0.2
0 3 0.3
0 4 0.4
1 0 1
1 1 1.1
1 2 1.2
1 3 1.3
1 4 1.4
2 0 2
2 1 2.1
2 2 2.2
2 3 2.3
2 4 2.4
3 0 3
3 1 3.1
3 2 3.2
3 3 3.3
3 4 3.4
t r 4 d 3
t l 4 u 3
t r 2 d 2
d 1 2
d 2 3
d 3 4
d 2 0
t r 2 d 2
t r 1 u 2
t r 1 d 3
t l 3
t d 1 l 1
t u 2
the first line contains the number of rows and columns, the next few lines contain the row and column and the value that is stored in that position. After that are the traverse lines and delete lines. I have the values read in perfectly and everything created, but i am not quite sure how i would go about reading in the traverse and delete lines. I want to set the first character of each traverse line which is denoted by a t to a traverse variable, the second character to a direction variable, the third character to a step variable, then the fourth would be the direction again and the 5th the step variable again. Then when it gets to the delete lines read in the first character as the action variable and then the second character to a row variable and 3rd character to a column variable. Also i am not quite sure how to read in the traverse line with two directions and then go about reading in the traverse line with only 1 direction and still have the values stored to the correct variables.
Here is my code
Node* currentObject;
Node a[50][50];
Node node;
Node* start;
if (!cin.eof())
{
cin>>row;
cin>>column;
cout<<row;
cout<<column;
for(int i=0;i<row;i++)
{
for ( int j = 0; j < column; j++ )
{
currentObject=&a[0][0];
cin>>rowpos;
cin>>colpos;
cin>>value2;
a[ rowpos ][ colpos ].value =value2 ;
if(rowpos-1>=0)
{
a[rowpos][colpos].top=&a[rowpos-1][colpos];
}
if(rowpos+1<=row)
{
a[rowpos][colpos].bottom=&a[rowpos+1][colpos];
}
if(colpos-1>=0)
{
a[rowpos][colpos].left=&a[rowpos][colpos-1];
}
if(colpos+1<=column)
{
a[rowpos][colpos].right=&a[rowpos][colpos+1];
}
}
}
}
while(!cin.eof())
{
if (!cin.eof())
{
/*getline(cin,action,' ');
getline(cin,dir,' ');
cin>>step;*/
/*if(action=="t")
{
if(dir=="r")
{
for(int i=0;i<step;i++)
{
currentObject=currentObject->right;
cout<<currentObject;
}
}
if(dir=="l")
{
for(int i =0;i<step;i++)
{
currentObject=currentObject->left;
cout<<currentObject;
}
}
if(dir=="u")
{
for(int i =0;i<step;i++)
{
currentObject=currentObject->top;
cout<<currentObject;
}
}
if(dir=="d")
{
for(int i =0;i<step;i++)
{
currentObject=currentObject->bottom;
cout<<currentObject;
}
}
}*/
}
}
}
It first reads in the row and column. Then sets the values to the rows and columns. After this the right,left,top,and bottom objects are set. Im just not sure how to read in the traverse and delete lines into variables, so i can then do the if statements to do my traversing. Any help would be really appreciated.