Note that there are some explanatory texts on larger screens.

plurals
  1. POfloating point exception c++ on a radix Sort function
    primarykey
    data
    text
    <p>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.</p> <p>The code compiles, but when run the error pops up. "Floating point exception (core dumped)"</p> <pre><code> vector&lt;int&gt; radixSort (vector&lt;int&gt; &amp;numbs, int maxA) { vector&lt;vector&lt;int&gt; &gt;temp1; vector&lt;vector&lt;int&gt; &gt;temp2; for (int i = 0; i &lt; 10 ; i++) { temp1.push_back(vector&lt;int&gt;()); temp2.push_back(vector&lt;int&gt;()); } int x = 1; int plc = 0; while (maxA/x &gt; 0) { plc = plc + 1; x = x * 10; } for (int i = 0; i &lt; (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 &gt; 0) { for (int i = 0; i &lt; 10 ; i++) { if (temp1[i].size() &gt; 0) { for (int j = 0; j &lt; 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 &lt; 10 ; i++) { temp1[i].clear(); } if (plc &gt; 0) { for (int i = 0; i &lt; 10 ; i++) { if (temp2[i].size() &gt; 0) { for (int j = 0; j &lt; 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 &lt; 10 ; i++) { temp2[i].clear(); } } } if (isTemp1 == true) { int y = 0; for (int i = 0; i &lt; 10 ; i++) { if (temp1[i].size() &gt; 0) { for (int j = 0; j &lt; temp1[i].size() ; j++) { numbs[y] = temp1[i][j]; y++; } } } } else { int y = 0; for (int i = 0; i &lt; 10 ; i++) { if (temp2[i].size() &gt; 0) { for (int j = 0; j &lt; temp2[i].size() ; j++) { numbs[y] = temp2[i][j]; y++; } } } } return numbs; } </code></pre> <p>thanks for the help seems to be working now when I found my errors here is the fixed copy</p> <pre><code>vector&lt;int&gt; radixSort (vector&lt;int&gt; &amp;numbs, int maxA) { vector&lt;vector&lt;int&gt; &gt;temp1; vector&lt;vector&lt;int&gt; &gt;temp2; for (int i = 0; i &lt; 10 ; i++) { temp1.push_back(vector&lt;int&gt;()); temp2.push_back(vector&lt;int&gt;()); } int x = 1; int plc = 0; while (maxA/x &gt; 0) { plc = plc + 1; x = x * 10; } for (int i = 0; i &lt; (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 &gt; 0) { for (int i = 0; i &lt; 10 ; i++) { if (temp1[i].size() &gt; 0) { for (int j = 0; j &lt; 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 &lt; 10 ; i++) { temp1[i].clear(); } if (plc &gt; 0) { for (int i = 0; i &lt; 10 ; i++) { if (temp2[i].size() &gt; 0) { for (int j = 0; j &lt; 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 &lt; 10 ; i++) { temp2[i].clear(); } } } if (isTemp1 == true) { int y = 0; for (int i = 0; i &lt; 10 ; i++) { if (temp1[i].size() &gt; 0) { for (int j = 0; j &lt; temp1[i].size() ; j++) { numbs[y] = temp1[i][j]; y++; } } } } else { int y = 0; for (int i = 0; i &lt; 10 ; i++) { if (temp2[i].size() &gt; 0) { for (int j = 0; j &lt; temp2[i].size() ; j++) { numbs[y] = temp2[i][j]; y++; } } } } return numbs; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload