Finding modes in C++











up vote
1
down vote

favorite












I am beginner in C++ (Data-structures and algorithms) and I need some help to write a better computation function in my int computemodes method. Is there way to write a better function that sorts the item count pair list in descending order by count. For example the item count pair list becomes,
{2,3},{4,3},{5,2}, {3,2}, {1,2}. Thanks for the help.



Right now it display as: 16 10 11 10 15 15 10 14 16 14 14 13 15 14 13 11 10 11 11 11 14 14 15 10 .




here is my code




    /*
the mode of a set of things is that thing that appears the greater number of times in the set
a set may have several modes
*/
int computemodes(int source, int size, int modes, int& msize)


{
/*
1. fill the modes array with zeroes
*/
fill(modes, size, 0);

/*
2. store the number of times each source element appears in the modes array.
if an element appears more than once in the source array then its counts appears
more than once the modes array.
source and modes form a parallel array structure
*/
for(int i = 0; i < size; i++)
modes[i] = count(source, size, source[i]);



/*
3. calculate the largest number in the modes array. this number is the number of
times the mode or modes appears in the source array
*/
int modevalue = findLargest(modes, size);

/*
4. assign -1 to the mode array elements that are less than the mode value
now only mode values in the modes array are not equal to -1.
the corresponding elements in the source array are the modes.
*/
for(int i = 0; i < size; i++)
if(modes[i] != modevalue) modes[i] = -1;





/*
5. we use the modes array to identify the source elements that are modes:
any element in the modes array that is not -1 corresponds to a mode in the
source array. if the mode is 1 then every source element is a mode
and no element in the modes array is -1; if the mode is greater than 1 then
a. many modes array entries are -1
b. the number of times a mode appears in the source equals its corresponding modes value
c. the number of modes array entries that are not -1 are the number of times the modes
appear in the source array

the following nested for loop transforms the modes array into an array in which
the first appearance of a mode in the source corresponds to a modes array entry
that is not -1 and subsequent appearances of this mode in the source correspond to
modes array entries that are -1.
*/
for(int i = 0; i < size; i++)
if(modes[i] != -1) //first appearance of the mode in the source
for(int j = i + 1; j < size; j++)
if(source[i] == source[j]) modes[j] = -1;
//subsequent appearances
/*
at this point the usage of the modes array changes.
heretofore, an entry that is not -1 in the modes array is the number of times
a mode appears in the source array. now an entry in the modes array is a mode.
the loop adds modes from the source array to the modes array.
msize serves 2 purposes:
a. it is number of modes copied so far.
b. it is the next free modes array position.
*/
msize = 0;
for (int i = 0; i < size; i++)
if (modes[i] != -1) //first occurrence of a mode in the source
{
modes[msize] = source[i];
msize++;
}
return modevalue;
}


updated code



 #include <ctime>
#include <iomanip>
#include <iostream>
#include <string>
#include <random>


#include <map>
using namespace std;

default_random_engine e(static_cast<unsigned>(time(NULL)));

void fill(int a, int size, int value)
{
for(int i = 0; i < size; i++)
a[i] = value;
}
void randomFill(int a, int size, int lb, int up)
{
uniform_int_distribution<int> u(lb, up);
for(int i = 0; i < size; i++)
a[i] = u(e);
}
void show(int a1d, int size)
{
for(int i = 0; i < size; i++)
cout << setw(2) << a1d[i] << ' ';
cout << endl;
}
int count(int a1d, int size, int value)
{
int vcount = 0;
for(int i = 0; i < size; i++)
if(a1d[i] == value) vcount++;
return vcount;
}
int findLargest(int a1d, int size)
{
int largest = a1d[0];
for(int i = 1; i < size; i++)
if(a1d[i] > largest) largest = a1d[i];
return largest;
}




void generatePairings(int* items, int itemcount, int start)
{
if(itemcount & 1)
return; // must be an even number of items

// is this a complete pairing?
if(start == itemcount)
{
// output pairings:
int i;
for(i = 0; i<itemcount; i+=2)
{
printf("[%d, %d] ", items[i], items[i+1]);
}
printf("n");
return;
}

// for the next pair, choose the first element in the list for the
// first item in the pair (meaning we don't have to do anything
// but leave it in place), and each of the remaining elements for
// the second item:
int j;
for(j = start+1; j<itemcount; j++)
{
// swap start+1 and j:
int temp = items[start+1];
items[start+1] = items[j];
items[j] = temp;

// recurse:
generatePairings(items, itemcount, start+2);

// swap them back:
temp = items[start+1];
items[start+1] = items[j];
items[j] = temp;
}
}

int main(void) {
int items[24] = {1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14,15,16,17,18,19,20,21,22,23,24};
generatePairings(items, 6, 0);

return 0;
}









share|improve this question









New contributor




Mike is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    I edited the title of your post to make it more clear what your code does, as that's the suggested use of the title as noted in the Titling section of the "How to Ask" help question. Let me know if I misunderstood. Also, welcome to Code Review!
    – user1118321
    28 mins ago










  • Thank you. Do you understand my question what It needs to be solved?
    – Mike
    20 mins ago












  • I get the gist of it. You're finding the mode of the data and want to find each entry in the array that equals one of the modes. Right? It wouldn't hurt to explain it in a little more detail.
    – user1118321
    6 mins ago










  • I will show you the updated code I have... I want something like my updated code but randomly change the values that I have in previous old code.
    – Mike
    5 mins ago










  • same functionality like my previous old code - but pairing when computing the mode. For example: sorts the item-count pair list in descending order by count. The item-count pair list becomes, {2,3},{4,3},{5,2}, {3,2}, {1,2} and the modes are clearly 2 and 4.
    – Mike
    2 mins ago















up vote
1
down vote

favorite












I am beginner in C++ (Data-structures and algorithms) and I need some help to write a better computation function in my int computemodes method. Is there way to write a better function that sorts the item count pair list in descending order by count. For example the item count pair list becomes,
{2,3},{4,3},{5,2}, {3,2}, {1,2}. Thanks for the help.



Right now it display as: 16 10 11 10 15 15 10 14 16 14 14 13 15 14 13 11 10 11 11 11 14 14 15 10 .




here is my code




    /*
the mode of a set of things is that thing that appears the greater number of times in the set
a set may have several modes
*/
int computemodes(int source, int size, int modes, int& msize)


{
/*
1. fill the modes array with zeroes
*/
fill(modes, size, 0);

/*
2. store the number of times each source element appears in the modes array.
if an element appears more than once in the source array then its counts appears
more than once the modes array.
source and modes form a parallel array structure
*/
for(int i = 0; i < size; i++)
modes[i] = count(source, size, source[i]);



/*
3. calculate the largest number in the modes array. this number is the number of
times the mode or modes appears in the source array
*/
int modevalue = findLargest(modes, size);

/*
4. assign -1 to the mode array elements that are less than the mode value
now only mode values in the modes array are not equal to -1.
the corresponding elements in the source array are the modes.
*/
for(int i = 0; i < size; i++)
if(modes[i] != modevalue) modes[i] = -1;





/*
5. we use the modes array to identify the source elements that are modes:
any element in the modes array that is not -1 corresponds to a mode in the
source array. if the mode is 1 then every source element is a mode
and no element in the modes array is -1; if the mode is greater than 1 then
a. many modes array entries are -1
b. the number of times a mode appears in the source equals its corresponding modes value
c. the number of modes array entries that are not -1 are the number of times the modes
appear in the source array

the following nested for loop transforms the modes array into an array in which
the first appearance of a mode in the source corresponds to a modes array entry
that is not -1 and subsequent appearances of this mode in the source correspond to
modes array entries that are -1.
*/
for(int i = 0; i < size; i++)
if(modes[i] != -1) //first appearance of the mode in the source
for(int j = i + 1; j < size; j++)
if(source[i] == source[j]) modes[j] = -1;
//subsequent appearances
/*
at this point the usage of the modes array changes.
heretofore, an entry that is not -1 in the modes array is the number of times
a mode appears in the source array. now an entry in the modes array is a mode.
the loop adds modes from the source array to the modes array.
msize serves 2 purposes:
a. it is number of modes copied so far.
b. it is the next free modes array position.
*/
msize = 0;
for (int i = 0; i < size; i++)
if (modes[i] != -1) //first occurrence of a mode in the source
{
modes[msize] = source[i];
msize++;
}
return modevalue;
}


updated code



 #include <ctime>
#include <iomanip>
#include <iostream>
#include <string>
#include <random>


#include <map>
using namespace std;

default_random_engine e(static_cast<unsigned>(time(NULL)));

void fill(int a, int size, int value)
{
for(int i = 0; i < size; i++)
a[i] = value;
}
void randomFill(int a, int size, int lb, int up)
{
uniform_int_distribution<int> u(lb, up);
for(int i = 0; i < size; i++)
a[i] = u(e);
}
void show(int a1d, int size)
{
for(int i = 0; i < size; i++)
cout << setw(2) << a1d[i] << ' ';
cout << endl;
}
int count(int a1d, int size, int value)
{
int vcount = 0;
for(int i = 0; i < size; i++)
if(a1d[i] == value) vcount++;
return vcount;
}
int findLargest(int a1d, int size)
{
int largest = a1d[0];
for(int i = 1; i < size; i++)
if(a1d[i] > largest) largest = a1d[i];
return largest;
}




void generatePairings(int* items, int itemcount, int start)
{
if(itemcount & 1)
return; // must be an even number of items

// is this a complete pairing?
if(start == itemcount)
{
// output pairings:
int i;
for(i = 0; i<itemcount; i+=2)
{
printf("[%d, %d] ", items[i], items[i+1]);
}
printf("n");
return;
}

// for the next pair, choose the first element in the list for the
// first item in the pair (meaning we don't have to do anything
// but leave it in place), and each of the remaining elements for
// the second item:
int j;
for(j = start+1; j<itemcount; j++)
{
// swap start+1 and j:
int temp = items[start+1];
items[start+1] = items[j];
items[j] = temp;

// recurse:
generatePairings(items, itemcount, start+2);

// swap them back:
temp = items[start+1];
items[start+1] = items[j];
items[j] = temp;
}
}

int main(void) {
int items[24] = {1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14,15,16,17,18,19,20,21,22,23,24};
generatePairings(items, 6, 0);

return 0;
}









share|improve this question









New contributor




Mike is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    I edited the title of your post to make it more clear what your code does, as that's the suggested use of the title as noted in the Titling section of the "How to Ask" help question. Let me know if I misunderstood. Also, welcome to Code Review!
    – user1118321
    28 mins ago










  • Thank you. Do you understand my question what It needs to be solved?
    – Mike
    20 mins ago












  • I get the gist of it. You're finding the mode of the data and want to find each entry in the array that equals one of the modes. Right? It wouldn't hurt to explain it in a little more detail.
    – user1118321
    6 mins ago










  • I will show you the updated code I have... I want something like my updated code but randomly change the values that I have in previous old code.
    – Mike
    5 mins ago










  • same functionality like my previous old code - but pairing when computing the mode. For example: sorts the item-count pair list in descending order by count. The item-count pair list becomes, {2,3},{4,3},{5,2}, {3,2}, {1,2} and the modes are clearly 2 and 4.
    – Mike
    2 mins ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am beginner in C++ (Data-structures and algorithms) and I need some help to write a better computation function in my int computemodes method. Is there way to write a better function that sorts the item count pair list in descending order by count. For example the item count pair list becomes,
{2,3},{4,3},{5,2}, {3,2}, {1,2}. Thanks for the help.



Right now it display as: 16 10 11 10 15 15 10 14 16 14 14 13 15 14 13 11 10 11 11 11 14 14 15 10 .




here is my code




    /*
the mode of a set of things is that thing that appears the greater number of times in the set
a set may have several modes
*/
int computemodes(int source, int size, int modes, int& msize)


{
/*
1. fill the modes array with zeroes
*/
fill(modes, size, 0);

/*
2. store the number of times each source element appears in the modes array.
if an element appears more than once in the source array then its counts appears
more than once the modes array.
source and modes form a parallel array structure
*/
for(int i = 0; i < size; i++)
modes[i] = count(source, size, source[i]);



/*
3. calculate the largest number in the modes array. this number is the number of
times the mode or modes appears in the source array
*/
int modevalue = findLargest(modes, size);

/*
4. assign -1 to the mode array elements that are less than the mode value
now only mode values in the modes array are not equal to -1.
the corresponding elements in the source array are the modes.
*/
for(int i = 0; i < size; i++)
if(modes[i] != modevalue) modes[i] = -1;





/*
5. we use the modes array to identify the source elements that are modes:
any element in the modes array that is not -1 corresponds to a mode in the
source array. if the mode is 1 then every source element is a mode
and no element in the modes array is -1; if the mode is greater than 1 then
a. many modes array entries are -1
b. the number of times a mode appears in the source equals its corresponding modes value
c. the number of modes array entries that are not -1 are the number of times the modes
appear in the source array

the following nested for loop transforms the modes array into an array in which
the first appearance of a mode in the source corresponds to a modes array entry
that is not -1 and subsequent appearances of this mode in the source correspond to
modes array entries that are -1.
*/
for(int i = 0; i < size; i++)
if(modes[i] != -1) //first appearance of the mode in the source
for(int j = i + 1; j < size; j++)
if(source[i] == source[j]) modes[j] = -1;
//subsequent appearances
/*
at this point the usage of the modes array changes.
heretofore, an entry that is not -1 in the modes array is the number of times
a mode appears in the source array. now an entry in the modes array is a mode.
the loop adds modes from the source array to the modes array.
msize serves 2 purposes:
a. it is number of modes copied so far.
b. it is the next free modes array position.
*/
msize = 0;
for (int i = 0; i < size; i++)
if (modes[i] != -1) //first occurrence of a mode in the source
{
modes[msize] = source[i];
msize++;
}
return modevalue;
}


updated code



 #include <ctime>
#include <iomanip>
#include <iostream>
#include <string>
#include <random>


#include <map>
using namespace std;

default_random_engine e(static_cast<unsigned>(time(NULL)));

void fill(int a, int size, int value)
{
for(int i = 0; i < size; i++)
a[i] = value;
}
void randomFill(int a, int size, int lb, int up)
{
uniform_int_distribution<int> u(lb, up);
for(int i = 0; i < size; i++)
a[i] = u(e);
}
void show(int a1d, int size)
{
for(int i = 0; i < size; i++)
cout << setw(2) << a1d[i] << ' ';
cout << endl;
}
int count(int a1d, int size, int value)
{
int vcount = 0;
for(int i = 0; i < size; i++)
if(a1d[i] == value) vcount++;
return vcount;
}
int findLargest(int a1d, int size)
{
int largest = a1d[0];
for(int i = 1; i < size; i++)
if(a1d[i] > largest) largest = a1d[i];
return largest;
}




void generatePairings(int* items, int itemcount, int start)
{
if(itemcount & 1)
return; // must be an even number of items

// is this a complete pairing?
if(start == itemcount)
{
// output pairings:
int i;
for(i = 0; i<itemcount; i+=2)
{
printf("[%d, %d] ", items[i], items[i+1]);
}
printf("n");
return;
}

// for the next pair, choose the first element in the list for the
// first item in the pair (meaning we don't have to do anything
// but leave it in place), and each of the remaining elements for
// the second item:
int j;
for(j = start+1; j<itemcount; j++)
{
// swap start+1 and j:
int temp = items[start+1];
items[start+1] = items[j];
items[j] = temp;

// recurse:
generatePairings(items, itemcount, start+2);

// swap them back:
temp = items[start+1];
items[start+1] = items[j];
items[j] = temp;
}
}

int main(void) {
int items[24] = {1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14,15,16,17,18,19,20,21,22,23,24};
generatePairings(items, 6, 0);

return 0;
}









share|improve this question









New contributor




Mike is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I am beginner in C++ (Data-structures and algorithms) and I need some help to write a better computation function in my int computemodes method. Is there way to write a better function that sorts the item count pair list in descending order by count. For example the item count pair list becomes,
{2,3},{4,3},{5,2}, {3,2}, {1,2}. Thanks for the help.



Right now it display as: 16 10 11 10 15 15 10 14 16 14 14 13 15 14 13 11 10 11 11 11 14 14 15 10 .




here is my code




    /*
the mode of a set of things is that thing that appears the greater number of times in the set
a set may have several modes
*/
int computemodes(int source, int size, int modes, int& msize)


{
/*
1. fill the modes array with zeroes
*/
fill(modes, size, 0);

/*
2. store the number of times each source element appears in the modes array.
if an element appears more than once in the source array then its counts appears
more than once the modes array.
source and modes form a parallel array structure
*/
for(int i = 0; i < size; i++)
modes[i] = count(source, size, source[i]);



/*
3. calculate the largest number in the modes array. this number is the number of
times the mode or modes appears in the source array
*/
int modevalue = findLargest(modes, size);

/*
4. assign -1 to the mode array elements that are less than the mode value
now only mode values in the modes array are not equal to -1.
the corresponding elements in the source array are the modes.
*/
for(int i = 0; i < size; i++)
if(modes[i] != modevalue) modes[i] = -1;





/*
5. we use the modes array to identify the source elements that are modes:
any element in the modes array that is not -1 corresponds to a mode in the
source array. if the mode is 1 then every source element is a mode
and no element in the modes array is -1; if the mode is greater than 1 then
a. many modes array entries are -1
b. the number of times a mode appears in the source equals its corresponding modes value
c. the number of modes array entries that are not -1 are the number of times the modes
appear in the source array

the following nested for loop transforms the modes array into an array in which
the first appearance of a mode in the source corresponds to a modes array entry
that is not -1 and subsequent appearances of this mode in the source correspond to
modes array entries that are -1.
*/
for(int i = 0; i < size; i++)
if(modes[i] != -1) //first appearance of the mode in the source
for(int j = i + 1; j < size; j++)
if(source[i] == source[j]) modes[j] = -1;
//subsequent appearances
/*
at this point the usage of the modes array changes.
heretofore, an entry that is not -1 in the modes array is the number of times
a mode appears in the source array. now an entry in the modes array is a mode.
the loop adds modes from the source array to the modes array.
msize serves 2 purposes:
a. it is number of modes copied so far.
b. it is the next free modes array position.
*/
msize = 0;
for (int i = 0; i < size; i++)
if (modes[i] != -1) //first occurrence of a mode in the source
{
modes[msize] = source[i];
msize++;
}
return modevalue;
}


updated code



 #include <ctime>
#include <iomanip>
#include <iostream>
#include <string>
#include <random>


#include <map>
using namespace std;

default_random_engine e(static_cast<unsigned>(time(NULL)));

void fill(int a, int size, int value)
{
for(int i = 0; i < size; i++)
a[i] = value;
}
void randomFill(int a, int size, int lb, int up)
{
uniform_int_distribution<int> u(lb, up);
for(int i = 0; i < size; i++)
a[i] = u(e);
}
void show(int a1d, int size)
{
for(int i = 0; i < size; i++)
cout << setw(2) << a1d[i] << ' ';
cout << endl;
}
int count(int a1d, int size, int value)
{
int vcount = 0;
for(int i = 0; i < size; i++)
if(a1d[i] == value) vcount++;
return vcount;
}
int findLargest(int a1d, int size)
{
int largest = a1d[0];
for(int i = 1; i < size; i++)
if(a1d[i] > largest) largest = a1d[i];
return largest;
}




void generatePairings(int* items, int itemcount, int start)
{
if(itemcount & 1)
return; // must be an even number of items

// is this a complete pairing?
if(start == itemcount)
{
// output pairings:
int i;
for(i = 0; i<itemcount; i+=2)
{
printf("[%d, %d] ", items[i], items[i+1]);
}
printf("n");
return;
}

// for the next pair, choose the first element in the list for the
// first item in the pair (meaning we don't have to do anything
// but leave it in place), and each of the remaining elements for
// the second item:
int j;
for(j = start+1; j<itemcount; j++)
{
// swap start+1 and j:
int temp = items[start+1];
items[start+1] = items[j];
items[j] = temp;

// recurse:
generatePairings(items, itemcount, start+2);

// swap them back:
temp = items[start+1];
items[start+1] = items[j];
items[j] = temp;
}
}

int main(void) {
int items[24] = {1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14,15,16,17,18,19,20,21,22,23,24};
generatePairings(items, 6, 0);

return 0;
}






c++ algorithm






share|improve this question









New contributor




Mike is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Mike is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 5 mins ago





















New contributor




Mike is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 1 hour ago









Mike

62




62




New contributor




Mike is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Mike is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Mike is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1




    I edited the title of your post to make it more clear what your code does, as that's the suggested use of the title as noted in the Titling section of the "How to Ask" help question. Let me know if I misunderstood. Also, welcome to Code Review!
    – user1118321
    28 mins ago










  • Thank you. Do you understand my question what It needs to be solved?
    – Mike
    20 mins ago












  • I get the gist of it. You're finding the mode of the data and want to find each entry in the array that equals one of the modes. Right? It wouldn't hurt to explain it in a little more detail.
    – user1118321
    6 mins ago










  • I will show you the updated code I have... I want something like my updated code but randomly change the values that I have in previous old code.
    – Mike
    5 mins ago










  • same functionality like my previous old code - but pairing when computing the mode. For example: sorts the item-count pair list in descending order by count. The item-count pair list becomes, {2,3},{4,3},{5,2}, {3,2}, {1,2} and the modes are clearly 2 and 4.
    – Mike
    2 mins ago














  • 1




    I edited the title of your post to make it more clear what your code does, as that's the suggested use of the title as noted in the Titling section of the "How to Ask" help question. Let me know if I misunderstood. Also, welcome to Code Review!
    – user1118321
    28 mins ago










  • Thank you. Do you understand my question what It needs to be solved?
    – Mike
    20 mins ago












  • I get the gist of it. You're finding the mode of the data and want to find each entry in the array that equals one of the modes. Right? It wouldn't hurt to explain it in a little more detail.
    – user1118321
    6 mins ago










  • I will show you the updated code I have... I want something like my updated code but randomly change the values that I have in previous old code.
    – Mike
    5 mins ago










  • same functionality like my previous old code - but pairing when computing the mode. For example: sorts the item-count pair list in descending order by count. The item-count pair list becomes, {2,3},{4,3},{5,2}, {3,2}, {1,2} and the modes are clearly 2 and 4.
    – Mike
    2 mins ago








1




1




I edited the title of your post to make it more clear what your code does, as that's the suggested use of the title as noted in the Titling section of the "How to Ask" help question. Let me know if I misunderstood. Also, welcome to Code Review!
– user1118321
28 mins ago




I edited the title of your post to make it more clear what your code does, as that's the suggested use of the title as noted in the Titling section of the "How to Ask" help question. Let me know if I misunderstood. Also, welcome to Code Review!
– user1118321
28 mins ago












Thank you. Do you understand my question what It needs to be solved?
– Mike
20 mins ago






Thank you. Do you understand my question what It needs to be solved?
– Mike
20 mins ago














I get the gist of it. You're finding the mode of the data and want to find each entry in the array that equals one of the modes. Right? It wouldn't hurt to explain it in a little more detail.
– user1118321
6 mins ago




I get the gist of it. You're finding the mode of the data and want to find each entry in the array that equals one of the modes. Right? It wouldn't hurt to explain it in a little more detail.
– user1118321
6 mins ago












I will show you the updated code I have... I want something like my updated code but randomly change the values that I have in previous old code.
– Mike
5 mins ago




I will show you the updated code I have... I want something like my updated code but randomly change the values that I have in previous old code.
– Mike
5 mins ago












same functionality like my previous old code - but pairing when computing the mode. For example: sorts the item-count pair list in descending order by count. The item-count pair list becomes, {2,3},{4,3},{5,2}, {3,2}, {1,2} and the modes are clearly 2 and 4.
– Mike
2 mins ago




same functionality like my previous old code - but pairing when computing the mode. For example: sorts the item-count pair list in descending order by count. The item-count pair list becomes, {2,3},{4,3},{5,2}, {3,2}, {1,2} and the modes are clearly 2 and 4.
– Mike
2 mins ago















active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");

StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Mike is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f209408%2ffinding-modes-in-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








Mike is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Mike is a new contributor. Be nice, and check out our Code of Conduct.













Mike is a new contributor. Be nice, and check out our Code of Conduct.












Mike is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Code Review Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f209408%2ffinding-modes-in-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin