배열의 모드를 찾기위한 함수를 작성해야합니다. 그러나 나는 알고리즘을 생각해 내는데 익숙하지 않다. 나는 다른 사람이 이것을 어떻게하는지 알기를 바라고있다.정렬 된 배열의 모드는 어떻게 찾습니까?
나는 배열의 크기와 각 요소의 값을 알고 있으며 배열을 최소에서 최대로 정렬했습니다.
배열
모드와 같은 모드 함수로 전달 될 = findMode (arrayPointer, sizePointer);
UPDATE : 사람이 저를 정렬 할 수 있습니다 경우 비록 내가이 알고리즘을 잡고이
int findMode(int *arrPTR, const int *sizePTR)
{
int most_found_element = arrPTR[0];
int most_found_element_count = 0;
int current_element = arrPTR[0];
int current_element_count = 0;
int count;
for (count = 0; count < *sizePTR; count++)
{
if(count == arrPTR[count])
current_element_count++;
else if(current_element_count > most_found_element)
{
most_found_element = current_element;
most_found_element_count = current_element_count;
}
current_element = count;
current_element_count=1;
}
return most_found_element;
}
여전히 문제가 발생합니다 시도했습니다
코멘트를 읽은 후. 저는 벡터를 사용한 적이 없으므로 다른 예제를 이해하지 못합니다.
시도해 본 내용과 코드를 게시 할 수 있습니까? 여기에 힌트가 있습니다. 배열을 반복하려고 시도하고 요소를 볼 때마다 요소 별 카운터를 하나씩 늘립니다. – asf107
"배열의 모드"란 무엇입니까? – wilhelmtell
배열의 _ 모드 _를 원하십니까? 무슨 뜻 이냐구? 아니면 _median_? 아니면 새로운 용어를 알아야합니까? 편집 : [모드는 진짜입니다! IR LERND] (http://www.mathsteacher.com.au/year8/ch17_stat/02_mean/mean.htm) –