1
배열에서 가장 빈번한 번호 하나와 반복되는 횟수를 찾는 메소드를 이미 만들었습니다. 그러나, 나의 업무는 동일한 양의 시간 반복되는 경우에 소수의 숫자를 찾는 것입니다. 다른 방법을 만들어야합니까? 아니면 어떻게 해결책을 찾을 수 있습니까?배열에서 FEW 가장 빈번한 요소를 찾습니다.
public static void most(Ring[] rings, int numCounter, out int popHallmark, out int amount)
{
amount = 1;
popHallmark = 0;
for (int i = 0; i < numCounter; i++)
{
int count = 0;
int temp = rings[i].HallMark;
count++;
for (int k = 0; k < numCounter; k++)
{
if (i != k)
{
if (k > i)
{
if (temp == rings[k].HallMark)
{
count++;
if (count > amount)
{
popHallmark = temp; // most popular hallmark
amount = count; //amount of rings that has this hallmark
}
}
}
}
}
}
}
이 그룹화 된 데이터는 주파수에 의해 주문하려면,'''rings.Take을 할 충분하다 (numCounter) .GroupBy (x => x.HallMark) .OrderByDescending (x => x.Count())''' – tym32167