내 재귀 선택 정렬 함수로 오류가 발생하는 것 같습니다. 이 짐승을 고치는 데 도움이된다면 도움이 될 것입니다.C에서 재귀 선택 정렬
#include <iostream>
#include <algorithm>
using namespace std;
void selection_sort(int[],int);
int main()
{
int a[5] = {5,4,3,2,1};
selection_sort(a,5);
return 0;
}
void selection_sort(int arr[],int n){
int max_pos;
if(n == 0) return;
int max = *max_element(arr,arr+n);
for(int i = 0; i < n;i++){
if(arr[max] == max){
max_pos = i;
}
}
swap(arr[max_pos],arr[n-1]);
selection_sort(arr,n--);
}
또한 이미 지적한대로 selection_sort (arr, - n); –