There is a class that is responsible for sorting fast. So, how to implement this piece (recursion) for a class, I can not understand it

/* recursion */ if (left < j) fast(N, left, j); if (i < right) fast(N, i, right); 

Here is the class itself

 class fast { private: int* N; int index; int left; int right; public: fast(int k) { index = k; left = 0; right = index - 1; N = new int[index]; } ~fast() { delete[] N; } void vvod() { srand(time(NULL)); for (int r = 0; r < index; r++) { N[r] = rand() % 10000 + 1; } } void vivod() { for (int g = 0; g < index; g++) { cout << N[g] << " " << endl; } } void sortirovka(int N, int left, int right) { int i = left, j = right; int tmp; int pivot = N[(left + right) / 2]; /* partition */ while (i <= j) { while (N[i] < pivot) i++; while (N[j] > pivot) j--; if (i <= j) { tmp = N[i]; N[i] = N[j]; N[j] = tmp; i++; j--; } }; /* recursion */ if (left < j) fast(N, left, j); if (i < right) fast(N, i, right); } }; 
  • 2
    “Recursion for a class” is not true. Recursion is a call from the procedure itself. - nick_n_a
  • @nick_n_a then how is it possible to implement sorting that uses recursion in classes? - Ilya Burmaka
  • You just call the class constructor and that's it; it does nothing, except, in your case, memory leaks. As nick_n_a noted, recursion is a function call from itself. In your case in the class you need to make a method that will call itself with the necessary parameters. Just do not forget the condition of exiting the function. - rudolfninja

0