Tableau 7d dynamique

Fermé
josch83 - 3 avril 2004 à 15:52
 mag71 - 3 avril 2004 à 15:59
voila un jolie petit divertissement, à vous de coder la procédure que permet de libérer la mémoire du tableau. ;)

----------------------------------------------------------------------------

#ifndef _VECT7D_H_
#define _VECT7D_H_
#include <iostream.h>

template<class myType1>
bool creatVector7d(myType1*******& vector7d, long dim1, long dim2, long dim3, long dim4, long dim5, long dim6, long dim7);

template<class myType1>
bool initVector7d(myType1******* vector7d, long dim1, long dim2, long dim3, long dim4, long dim5, long dim6, long dim7, myType1 value = NULL);

template<class myType1>
bool showVector7d(myType1******* vector7d, long dim1, long dim2, long dim3, long dim4, long dim5, long dim6, long dim7);

template<class myType1>
bool creatVector7d(myType1*******& vector7d, long dim1, long dim2, long dim3, long dim4, long dim5, long dim6, long dim7)
{
long i, j, k, l, m, n;

vector7d = new myType1******[dim1];

for(i = 0; i < dim1; i++)
{
*(vector7d + i) = new myType1*****[dim2];
for(j = 0; j < dim2; j++)
{
*(*(vector7d + i) + j) = new myType1****[dim3];
for(k = 0; k < dim3; k++)
{
*(*(*(vector7d + i) + j) + k) = new myType1***[dim4];
for(l = 0; l < dim4; l++)
{
*(*(*(*(vector7d + i) + j) + k) + l) = new myType1**[dim5];
for(m = 0; m < dim5; m++)
{
*(*(*(*(*(vector7d + i) + j) + k) + l) + m) = new myType1*[dim6];
for(n = 0; n < dim6; n++)
{
*(*(*(*(*(*(vector7d + i) + j) + k) + l) + m) + n) = new myType1[dim7];
}
}
}
}
}
}

return true;
}

template<class myType1>
bool initVector7d(myType1******* vector7d, long dim1, long dim2, long dim3, long dim4, long dim5, long dim6, long dim7, myType1 value)
{
long i, j, k, l, m, n, o;

for(i = 0; i < dim1; i++)
{
for(j = 0; j < dim2; j++)
{
for(k = 0; k < dim3; k++)
{
for(l = 0; l < dim4; l++)
{
for(m = 0; m < dim5; m++)
{
for(n = 0; n < dim6; n++)
{
for(o = 0; o < dim7; o++)
{
*(*(*(*(*(*(*(vector7d + i) + j) + k) + l) + m) + n) + o) = value;
}
}
}
}
}
}
}
return true;
}

template<class myType1>
bool showVector7d(myType1******* vector7d, long dim1, long dim2, long dim3, long dim4, long dim5, long dim6, long dim7)
{
long i, j, k, l, m, n, o;

for(i = 0; i < dim1; i++)
{
for(j = 0; j < dim2; j++)
{
for(k = 0; k < dim3; k++)
{
for(l = 0; l < dim4; l++)
{
for(m = 0; m < dim5; m++)
{
for(n = 0; n < dim6; n++)
{
for(o = 0; o < dim7; o++)
{
cout
<< "[" << i << "]"
<< "[" << j << "]"
<< "[" << k << "]"
<< "[" << l << "]"
<< "[" << m << "]"
<< "[" << n << "]"
<< "[" << o << "]"
<< " = "
<< &(*(*(*(*(*(*(*(vector7d + i) + j) + k) + l) + m) + n) + o))
<< endl;
}
}
}
}
}
}
}
return true;
}
#endif
A voir également:

1 réponse

Mais bien sûr... :-/
0