I'm new to using c++ so this may be a vector issue. I'm getting a floating point error. I don't think this is a divide by zero error. Any help would be appreciated.
The code compiles, but when run the error pops up. "Floating point exception (core dumped)"
vector<int> radixSort (vector<int> &numbs, int maxA)
{
vector<vector<int> >temp1;
vector<vector<int> >temp2;
for (int i = 0; i < 10 ; i++)
{
temp1.push_back(vector<int>());
temp2.push_back(vector<int>());
}
int x = 1;
int plc = 0;
while (maxA/x > 0)
{
plc = plc + 1;
x = x * 10;
}
for (int i = 0; i < (int)numbs.size(); i++)
{
int aryLoc = numbs[i] % 10;
temp1[aryLoc].push_back(numbs[i]);
}
plc = plc - 1;
int modDiv = 100;
int intDiv = 10;
bool isTemp1 = true;
while (plc > 0)
{
for (int i = 0; i < 10 ; i++)
{
if (temp1[i].size() > 0)
{
for (int j = 0; j < temp1[i].size() ; j++)
{
int aryLoc = temp1[i][j] % modDiv;
aryLoc = temp1[i][j] / intDiv;
temp2[aryLoc].push_back(numbs[i]);
modDiv = modDiv * 10;
intDiv = intDiv * 10;
}
}
}
plc = plc - 1;
isTemp1 = false;
for (int i = 0; i < 10 ; i++)
{
temp1[i].clear();
}
if (plc > 0)
{
for (int i = 0; i < 10 ; i++)
{
if (temp2[i].size() > 0)
{
for (int j = 0; j < temp2[i].size() ; j++)
{
int aryLoc = temp2[i][j] % modDiv;
aryLoc = temp2[i][j] / intDiv;
temp1[aryLoc].push_back(numbs[i]);
modDiv = modDiv * 10;
intDiv = intDiv * 10;
}
}
}
plc = plc - 1;
isTemp1 = true;
for (int i = 0; i < 10 ; i++)
{
temp2[i].clear();
}
}
}
if (isTemp1 == true)
{
int y = 0;
for (int i = 0; i < 10 ; i++)
{
if (temp1[i].size() > 0)
{
for (int j = 0; j < temp1[i].size() ; j++)
{
numbs[y] = temp1[i][j];
y++;
}
}
}
}
else
{
int y = 0;
for (int i = 0; i < 10 ; i++)
{
if (temp2[i].size() > 0)
{
for (int j = 0; j < temp2[i].size() ; j++)
{
numbs[y] = temp2[i][j];
y++;
}
}
}
}
return numbs;
}
thanks for the help seems to be working now when I found my errors here is the fixed copy
vector<int> radixSort (vector<int> &numbs, int maxA)
{
vector<vector<int> >temp1;
vector<vector<int> >temp2;
for (int i = 0; i < 10 ; i++)
{
temp1.push_back(vector<int>());
temp2.push_back(vector<int>());
}
int x = 1;
int plc = 0;
while (maxA/x > 0)
{
plc = plc + 1;
x = x * 10;
}
for (int i = 0; i < (int)numbs.size(); i++)
{
int aryLoc = numbs[i] % 10;
temp1[aryLoc].push_back(numbs[i]);
}
plc = plc - 1;
int modDiv = 100;
int intDiv = 10;
bool isTemp1 = true;
while (plc > 0)
{
for (int i = 0; i < 10 ; i++)
{
if (temp1[i].size() > 0)
{
for (int j = 0; j < temp1[i].size() ; j++)
{
int aryLoc = temp1[i][j] % modDiv;
aryLoc = aryLoc / intDiv;
temp2[aryLoc].push_back(temp1[i][j]);
}
}
}
modDiv = modDiv * 10;
intDiv = intDiv * 10;
plc = plc - 1;
isTemp1 = false;
for (int i = 0; i < 10 ; i++)
{
temp1[i].clear();
}
if (plc > 0)
{
for (int i = 0; i < 10 ; i++)
{
if (temp2[i].size() > 0)
{
for (int j = 0; j < temp2[i].size() ; j++)
{
int aryLoc = temp2[i][j] % modDiv;
aryLoc = aryLoc / intDiv;
temp1[aryLoc].push_back(temp2[i][j]);
}
}
}
modDiv = modDiv * 10;
intDiv = intDiv * 10;
plc = plc - 1;
isTemp1 = true;
for (int i = 0; i < 10 ; i++)
{
temp2[i].clear();
}
}
}
if (isTemp1 == true)
{
int y = 0;
for (int i = 0; i < 10 ; i++)
{
if (temp1[i].size() > 0)
{
for (int j = 0; j < temp1[i].size() ; j++)
{
numbs[y] = temp1[i][j];
y++;
}
}
}
}
else
{
int y = 0;
for (int i = 0; i < 10 ; i++)
{
if (temp2[i].size() > 0)
{
for (int j = 0; j < temp2[i].size() ; j++)
{
numbs[y] = temp2[i][j];
y++;
}
}
}
}
return numbs;
}