Generic Usenet Account
2007-05-17 23:41:30 UTC
I have this simple program that maps elements with multiple indices,
within an n-dimensional space, into a unique number based on their
location within the multi-dimensional array. For some reason this
program is dumping core. For the life in me, I cannot figure out.
why Any help will be appreciated. Source code follows:
-- Gus
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <iterator>
#include <string>
#include <list>
using namespace std;
#define NUM_INDICES 3
#define HI_INDEX NUM_INDICES-1
#define LO_INDEX 0
int maxIdxVal[NUM_INDICES] = {2, 3, 4};
bool
print_indices(size_t value)
{
// if(value >= (2 * 3 * 4)) return false;
list<int> indices;
size_t residue = value;
for(int cur_idx = HI_INDEX; cur_idx >= LO_INDEX; cur_idx--)
{
size_t idxVal;
idxVal = residue % maxIdxVal[cur_idx];
residue /= maxIdxVal[cur_idx];
indices.push_front(idxVal);
}
copy (indices.begin(), indices.end(), ostream_iterator<int> (cout,
"\t"));
cout << endl;
}
int
main()
{
print_indices(14);
}
within an n-dimensional space, into a unique number based on their
location within the multi-dimensional array. For some reason this
program is dumping core. For the life in me, I cannot figure out.
why Any help will be appreciated. Source code follows:
-- Gus
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <iterator>
#include <string>
#include <list>
using namespace std;
#define NUM_INDICES 3
#define HI_INDEX NUM_INDICES-1
#define LO_INDEX 0
int maxIdxVal[NUM_INDICES] = {2, 3, 4};
bool
print_indices(size_t value)
{
// if(value >= (2 * 3 * 4)) return false;
list<int> indices;
size_t residue = value;
for(int cur_idx = HI_INDEX; cur_idx >= LO_INDEX; cur_idx--)
{
size_t idxVal;
idxVal = residue % maxIdxVal[cur_idx];
residue /= maxIdxVal[cur_idx];
indices.push_front(idxVal);
}
copy (indices.begin(), indices.end(), ostream_iterator<int> (cout,
"\t"));
cout << endl;
}
int
main()
{
print_indices(14);
}