Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have a redundant check causing an infinite loop.</p> <pre><code>void sortNumbers() { ... int check = 1; if( check != 0 ) { ... sortNumbers(); } } </code></pre> <p>Now, since this is clearly homework, I'll just give some general advice. In general, you use recursion to make a problem of a particular size smaller. Figure out what part of the problem is getting smaller each iteration, and just make each iteration a recursive call instead of a loop (hint: this means you'll probably want to pass some value into the method to tell you the size and/or location of the current iteration). And remember to have a check either at the beginning of the method or before you recurse to check the size of the problem.</p> <hr> <pre><code>void loop() { int topLevel = 0; int currentSort = 0; /* You never initialize this - what's supposed to be in it? */ int numbers [49]; int sizeOfArray = sizeof(numbers)/sizeof(int); /* Two things here: you're passing an array (numbers) in where the sortNumbers() function has it declared as an int; and the return value is declared as an int, but you're storing it into an array. */ numbers = sortNumbers(topLevel,currentSort,sizeOfArray,numbers); } /* You're going to have to change this method signature - you're working with arrays, not plain ints. You're changing numbers[] inline, so you don't need to return anything. */ int sortNumbers(int p,int c,int l,int numbers) { /* The first iteration has c = 0, so [c-1] is going to be out-of-bounds. Also, when c = l, [c] will be out of bounds. */ if( numbers[c-1] &gt; numbers[c] ) { int temp = numbers[c-1]; numbers[c-1] = numbers[c]; numbers[c] = temp; } if( c == l ) { c = 0; p++; } if( p == l+1 ) { return numbers; } return sortNumbers(p,c+1,l, numbers); } </code></pre> <p>This isn't how I was thinking of doing it, but I believe it should work once you fix the problems I've pointed out (and possibly some I missed).</p>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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