hi guys...i'm a new member here..i have a problem in my work and i hope anyone here can help me.
i have a data and this data actually is read from .txt file format. here, i give u an example of this data.
0 1
0 7
1 0
1 2
2 1
2 3
2 5
3 2
4 5
4 7
5 2
5 4
6 7
7 0
7 4
7 6
left side is the index of mesh and the right side is the neighbor for each mesh
what i want is, i want to arrange this data to be like this. for each mesh, it will find its own neighbor.
for example, index mesh 0. 0 has two neighbor.there are 1 and 7 whereas mesh 2 has 3 neighbors. there are 1 3 5. so the data that i want must be like this (below)..
0 1 7
1 0 2
2 1 3 5
3 2
4 5 7
5 2 4
6 7
7 0 4 6
i already code the algorithm..
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
|
void readdata3()
{
ifstream infile;
infile.open("nei.txt");
f = new int*[p];
for(int i=0;i<p;i++)
f[i] = new int [2];
g = new int*[p];
for(int j=0;j<p;j++)
g[j] = new int [3];
for(int i=0;i<p;i++)
{
infile >> f[i][0] >> f[i][1];
}
for(int j=2 ; j< p ;j++)
{
if((f[j][0] != f[j-1][0]) && (f[j-1][0] != f[j-2][0]) && (f[j][0] != f[j-2][0]))
{
g[j][0] = f[j-1][1];
cout << g[j][0] ;
}
else if((f[j][0] == f[j-1][0]) && (f[j-1][0] != f[j-2][0]) && (f[j-2][0] != f[j][0]))
{
g[j][0] = f[j-2][1];
cout << g[j][0] ;
}
else if((f[j][0] == f[j-1][0]) && (f[j-1][0] == f[j-2][0]) && (f[j-2][0] == f[j][0]))
{
g[j][0] = f[j-2][1];
g[j][1] = f[j-1][1];
g[j][2] = f[j][1];
cout << g[j][0] << " " << g[j][1]<< " " << g[j][2] <<endl;
}
else if((f[j-1][0] == f[j-2][0]) )
{
g[j][0] = f[j-2][1];
g[j][1] = f[j-1][1];
cout << g[j][0] << " " << g[j][1] << " " << endl;
}
}
}
| |
but this program cannot give what i want...it has a problem to read the mesh that have a same value in the previous mesh and previous-previous mesh (don't know how to say)...
let say, i=9, then if the value of f[8] = f[7]...that it will return the value of g[i] = f[7], g[i+1] = f[8]...for certain cases it work..but for some cases, it don't..i stuck here..
i hope anyone can help me. i really appreciate ur help...
thanks buddy.. :(