c++ - least frequent common number from a int array -
I want to get the least common number from an integer array, I have written the code but it is not working properly Here's my argument, 1. Sort the array 2. Update the Mid Common Counter 3. If all are unique
and the code below,
static integer min_loc; // minimum price position constant end min_cnt; Int all_uniqFlag = true; Zero atleast (int data [], int n) {int rcount = 0; // repeat count counter int mcount = n; // minimum redirect counter; // array is already sorted, we just need at least the normal value. For (int i = 0; i i-++) {// Case A: 1 1 2 2 2 3 3 3 3 4 5 5 5: The result should be 4 / Case B: 1 2 3 4 5 6 7 (All the unique numbers and common values should therefore be printed on all values // //) C: 1 1 2 2 3 3 4 4 (All numbers have the same frequency, so display them all Required) cout & lt; & Lt; "Data [i]:" & lt; & Lt; Data [i] & lt; & Lt; "Data [i + 1]:" & lt; & Lt; Data [i + 1] & lt; & Lt; "I =" & lt; & Lt; I & lt; & Lt; Endl; If (data [i]! = Data [i + 1]) {// mcount = 0; // min_loc = i; // Return; } If (data [i] == data [i + 1]) {all_uniqFlag = false; Rcount ++; } And if (rcount & lt; mcount) {mcount = rcount; Min_loc = i; // data [i]; }} Min_cnt = mcount; } As mentioned in the comment only case B works and case A and C are not working, can you help me fix this problem?
List Scan in the list with each element in the list with the last element Comparison array If the element matches, it grows by 1 If the element does not match then the new element is outside array and the array index 1 is scanned one time, there will be all the specific elements in the outside array Outside [] [0] and their frequencies left R [] [1] - Scan through frequency list (
outside [] [1] - Finally Element list
outside [] [0] and print the elements whose frequency matches the lowest frequency .
< code> # include & lt; stdio.h & gt; #include & lt; stdlib.h & gt; #define N 8 int main () {// int data [n] = {1,2, 3,4,5,6,7}; int data [n] = {1,1,2,2,3,3,4,4}; // int data [n] = {1,1,2, 2,2,3,3,3,5,5,5,5,5}; Int'l [N] [2]; Int i = 0, index = 0; For (i = 0; i
Comments
Post a Comment