Note that there are some explanatory texts on larger screens.

plurals
  1. POInfinite computation of qsort
    primarykey
    data
    text
    <p>i am realsing qsort algorithm, according on Korman. But there is infinite computation, when i trying to start it. I suppose, that problem is in partition. My programms reads from file, first number in file-line is counting of numbers to sort, and next go all numbers</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; int swap(int &amp;a, int &amp;b); int sorting(int *array, int &amp;b, int &amp;l); int partition(int *array ,int &amp;begin, int &amp;last); int main() { FILE* pFile=fopen("input.txt", "r"); //fopen("input.txt", "r"); //fopen("output.txt", "w"); int n; int begin=0; fscanf(pFile, "%d", &amp;n); int* array=(int*)malloc(n*sizeof(int)); for (int i=0; i&lt;n; ++i) fscanf(pFile,"%d", &amp;array[i]); int n1=n-1; sorting(array, begin, n1); printf("JJJJ"); for (int i=0; i&lt;n; ++i) printf("%d ", array[i]); printf("\n"); fclose(pFile); free(array); return 0; } int sorting(int* array, int &amp;b, int &amp;l) { int pivot,pivot1; if(b&lt;l) { pivot=partition(array, b, l); printf("MAXMAX321"); int a=pivot-1; sorting(array, b, a); printf("MAXMAX123"); pivot1=pivot+1; sorting(array, pivot1, l); printf("MAXMAX"); } return 0; } int partition(int* array, int &amp;b, int &amp;l) { int x=array[b]; int i=b; int j=l; while(true) { while(array[j]&gt;x){ printf("AHAH"); --j; } while(array[i]&lt;x){ printf("AZAZA"); ++i; } if(i&lt;j) swap(array[i],array[j]); else return j; } } int swap(int &amp;x, int &amp;y) { x=x+y; y=x-y; x=x-y; return 0; } </code></pre> <p>Thank you in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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. 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