I need to count the number of times each number appears in an array. I have no idea what to do in order to do this can i change the sort function to do this? or do i need another function to go through the array after it is sorted?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void sort(int numlist[], int size)
{
int out, in, temp;
for (out = 0; out < size-1; out++) //for each element index
for (in = out+1; in < size; in++) //compare with one element index down
if (numlist[out] > numlist[in]) //if out element index is greater than
{ //in element index
temp = numlist[in]; //swap them
numlist[in] = numlist[out];
numlist[out] = temp;
}
}
void sort(int numlist[], int size)
{
int out, in, temp;
for (out = 0; out < size-1; out++) // for each element index
for (in = out+1; in < size; in++) // compare with one element index down
if (numlist[out] > numlist[in]) // if out element index is greater than
{ // in element index
temp = numlist[in]; // swap them
numlist[in] = numlist[out];
numlist[out] = temp;
}
}
//
void count_distinct(int numlist[], int size, int distinct[])
{
int out, in, temp = 0;
for (out = 0; out < size-1; out++) // for each element index
for (in = out+1; in < size; in++) // compare with one element index down
if (numlist[out] = numlist[in]) // if out element index equals
{ // in element index
temp++; // increase temp
distinct[in] = temp;
temp = 0;
}
}