Hello!
I am facing a complex problem with a 2 dimensional array. I would be grateful if someone could help.
Here is my code:
std::string str1 = "ABABA";
std::string str2 = "BBBBBAAA";
double diag;
typedef std::pair<double, Direction> Cell;
matrix<Cell> m (str1.size()+1, str2.size()+1);
// Initialisation.
for(size_t i=0;i<m.size1();++i)
{
m.at_element(i, 0).first = static_cast<float>(i)*(-1.f);
}
for(size_t j=1;j<m.size2();++j)
{
m.at_element(0, j).first = static_cast<float>(j)*(-1.f);
}
// Operations
for(size_t i = 1; i<m.size1(); ++i)
{
for(size_t j = 1; j<m.size2(); ++j)
{
diag = m.at_element(i-1, j-1).first;
diag += 1;
}
}
//Display
std::cout<<" ";
for(size_t j=0;j<m.size2 ();++j)
{
std::cout << str2[j] << " ";
}
std::cout << "\n";
for(size_t i=0;i<m.size1 ();++i)
{
if(i==0)
{
std::cout <<" ";
}
else
{
std::cout << str1[i-1]<<" ";
}
for(size_t j=0;j<m.size2();++j)
{
std::cout << m.at_element(i,j).first<<" ";
}
std::cout <<"\n";
}
std::string str1 = "ABABA";
std::string str2 = "BBBBBAAA";
double diag;
typedef std::pair<double, Direction> Cell;
matrix<Cell> m (str1.size()+1, str2.size()+1);
// Initialisation.
for(size_t i=0;i<m.size1();++i)
{
m.at_element(i, 0).first = static_cast<float>(i)*(-1.f);
}
for(size_t j=1;j<m.size2();++j)
{
m.at_element(0, j).first = static_cast<float>(j)*(-1.f);
}
// Operations
for(size_t i = 1; i<m.size1(); ++i)
{
for(size_t j = 1; j<m.size2(); ++j)
{
diag = m.at_element(i-1, j-1).first;
diag += 1;
}
}
//Display
std::cout<<" ";
for(size_t j=0;j<m.size2 ();++j)
{
std::cout << str2[j] << " ";
}
std::cout << "\n";
for(size_t i=0;i<m.size1 ();++i)
{
if(i==0)
{
std::cout <<" ";
}
else
{
std::cout << str1[i-1]<<" ";
}
for(size_t j=0;j<m.size2();++j)
{
std::cout << m.at_element(i,j).first<<" ";
}
std::cout <<"\n";
}
To copy to clipboard, switch view to plain text mode
The compilation is OK, but at the execution, I have only zeros in my cells.
Question: What could be the source of this mistake?
I would grateful to anyone you could help.
Thanks in advance.
Bookmarks