Frequency Count - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Frequency Count

texmommyof4texmommyof4 Posts: 13Member
Trying to work with 3 arrays. Taking an original finding the duplicates and counting the dupes and the new elements in the dupe array. Here is the code I have so far. It doesn't work. Asking for suggestions to where I am going wrong.
[code]

void frequencyCount(short original[],short nonduplicate[], short count[],short& countNew,short size)
{
short value=0;
short k=0;
short m=0;

nonduplicate[0] = original[0];//since I know first element is not yet duplicated I assign it to element 0
count[0]=1; //also nothing in Count yet so 0 element of count will count be 1 until element 0 is duped the should inc.
countNew=1;//new element in dupe array so element count is 1;

for(k=1;k<size;k++)//assign 1 to k because want to start now with that element in original array.
{
value=original[k];//do I even need the variable value?
if(value==nonduplicate[m])
count[m++];//if the value is a duplicate inc the value in the element of count array
else
m++; //otherwise put the nondupe in nondupe array
nonduplicate[m]=value;
count[m]=1;//make the count 1 for new num
countNew++;//new element count

}

}
[code]

Comments

  • stoberstober Posts: 9,765Member ✭✭✭
    I think it is missiong some parentheses

    : [code]
    :
    : void frequencyCount(short original[],short nonduplicate[], short count[],short& countNew,short size)
    : {
    : short value=0;
    : short k=0;
    : short m=0;
    :
    : nonduplicate[0] = original[0];//since I know first element is not yet duplicated I assign it to element 0
    : count[0]=1; //also nothing in Count yet so 0 element of count will count be 1 until element 0 is duped the should inc.
    : countNew=1;//new element in dupe array so element count is 1;
    :
    : for(k=1;k<size;k++)//assign 1 to k because want to start now with that element in original array.
    : {
    : value=original[k];//do I even need the variable value?
    : if(value==nonduplicate[m])
    : count[m++];//if the value is a duplicate inc the value in the element of count array
    : else
    [red] {[/red]
    : m++; //otherwise put the nondupe in nondupe array
    : nonduplicate[m]=value;
    : count[m]=1;//make the count 1 for new num
    : countNew++;//new element count
    [red] }[/red]
    :
    : }
    :
    : }
    : [/code]
    :
  • texmommyof4texmommyof4 Posts: 13Member
    :[blue]Thank you! :)[/blue]
    I think it is missiong some parentheses
    :
    : : [code]
    : :
    : : void frequencyCount(short original[],short nonduplicate[], short count[],short& countNew,short size)
    : : {
    : : short value=0;
    : : short k=0;
    : : short m=0;
    : :
    : : nonduplicate[0] = original[0];//since I know first element is not yet duplicated I assign it to element 0
    : : count[0]=1; //also nothing in Count yet so 0 element of count will count be 1 until element 0 is duped the should inc.
    : : countNew=1;//new element in dupe array so element count is 1;
    : :
    : : for(k=1;k<size;k++)//assign 1 to k because want to start now with that element in original array.
    : : {
    : : value=original[k];//do I even need the variable value?
    : : if(value==nonduplicate[m])
    : : count[m++];//if the value is a duplicate inc the value in the element of count array
    : : else
    : [red] {[/red]
    : : m++; //otherwise put the nondupe in nondupe array
    : : nonduplicate[m]=value;
    : : count[m]=1;//make the count 1 for new num
    : : countNew++;//new element count
    : [red] }[/red]
    : :
    : : }
    : :
    : : }
    : : [/code]
    : :
    :

Sign In or Register to comment.