d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Array Frequency Counter > Need Help To Count Frequency Of Numbers
Add Reply New Topic New Poll
Member
Posts: 1,478
Joined: Jan 19 2016
Gold: 0.00
May 19 2017 03:35am
I need to output the number and next to it, the number of frequency that number came up. I need to use two arrays. one for inputting a list of numbers in and 2nd array is for the frequency counter. I am having a hard time with how to increment the counter array for each element.

Member
Posts: 36,123
Joined: Jul 18 2008
Gold: 2,407.00
May 19 2017 05:02am
You could use a hash table instead of a second array.
Member
Posts: 27,177
Joined: Mar 27 2008
Gold: 445.00
May 19 2017 05:17am
(Pseudo code)

ArrayOfNum{...};
InstancesOfNum {...};

Variable x, y= 0; // variables to count on

For ( x < length of ArrayOfNum)
{
For ( y < length of ArrayOfNum)
{
If (ArrayOfNum(x) equals ArrayOfNum(y)
{
InstancesOfNum(x)++;
}
}
}

This post was edited by ROM on May 19 2017 05:17am
Member
Posts: 1,478
Joined: Jan 19 2016
Gold: 0.00
May 19 2017 11:56pm
Quote (ROM @ May 19 2017 03:17am)
(Pseudo code)

ArrayOfNum{...};
InstancesOfNum {...};

Variable x, y= 0; // variables to count on

For ( x < length of ArrayOfNum)
{
For ( y < length of ArrayOfNum)
{
If (ArrayOfNum(x) equals ArrayOfNum(y)
{
InstancesOfNum(x)++;
}
}
}


tried this but It couldn't fully worked. I figured it out but this code right here lead me through it.
Member
Posts: 27,177
Joined: Mar 27 2008
Gold: 445.00
May 20 2017 05:37am
Quote (mrbabydaddy @ May 20 2017 01:56am)
tried this but It couldn't fully worked. I figured it out but this code right here lead me through it.


Glad it helped. It was of course just pseudo code to lead you on to the right track. :)
Member
Posts: 1,478
Joined: Jan 19 2016
Gold: 0.00
May 20 2017 07:37am
Quote (ROM @ May 20 2017 03:37am)
Glad it helped. It was of course just pseudo code to lead you on to the right track. :)


yeah tyty!
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll