Advertisement
Guest User

Ellrad Vector

a guest
Aug 1st, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. int findMode(int arrayName[], int arraySize)
  9. {
  10.     // Sorts Array in ascending order
  11.     sort(arrayName, arrayName + arraySize);
  12.     int frequency2 = 0;
  13.     //vector<int> vectorName;
  14.  
  15.     for (int i = 0; i < arraySize; i++)
  16.         cout << arrayName[i] << endl;
  17.  
  18.     // Numbers in array are now checked for frequency
  19.  
  20.     for (int i = 0; i < arraySize; i++)
  21.     {
  22.         int found = 0;
  23.  
  24.         for (int j = 0; j < i; j++)
  25.         {
  26.             if (arrayName[i] == arrayName[j])
  27.                 found++;
  28.         }
  29.  
  30.         if (found == 0)
  31.         {
  32.             int frequency = 1;
  33.  
  34.             for (int j = i + 1; j < arraySize; j++)
  35.             {
  36.                 if (arrayName[i] == arrayName[j])
  37.                 {
  38.                     frequency++;
  39.                    
  40.                 }
  41.             }
  42.         }
  43.     }
  44.    
  45. //pasted   
  46.  
  47.     /**for (int i = 0; i < arraySize; i++)
  48.         cout << arrayName[i] << endl; ***/
  49.  
  50.     // Numbers in array are now checked for frequency
  51.  
  52.     for (int i = 0; i < arraySize; i++)
  53.     {
  54.         int found = 0;
  55.  
  56.         for (int j = 0; j < i; j++)
  57.         {
  58.             if (arrayName[i] == arrayName[j])
  59.                 found++;
  60.         }
  61.  
  62.         if (found == 0)
  63.         {
  64.             int frequency = 1;
  65.  
  66.             for (int j = i + 1; j < arraySize; j++)
  67.             {
  68.                 if (arrayName[i] == arrayName[j])
  69.                 {
  70.                     frequency++;
  71.  
  72.                     if (frequency2 == frequency)
  73.                     {
  74.                         vector<int> vectorName;
  75.                         vectorName.push_back(arrayName[i]);
  76.                         return vectorName;
  77.  
  78.                        
  79.                        
  80.                     }
  81.  
  82.                 }
  83.  
  84.             }
  85.  
  86.         }
  87.     }
  88.    
  89. }
  90.  
  91.            
  92.                 /** if (frequency2 == frequency)
  93.                     cout << arrayName[i] << ":" << frequency << endl;  */
  94.  
  95.            
  96.            
  97.  
  98.  
  99.  
  100.  
  101. int main()
  102. {
  103.     cout << "Hi" << endl;
  104.    
  105.     vector <int> vectorName;
  106.     int arrayName1[] = { 1, 5, 6, 1, 5, 2, 4, 8, 1, 6, 5, 6 };
  107.     findMode(arrayName1, 12);
  108.     for (int i = 0; i < vectorName.size(); i++)
  109.         cout << vectorName[i] << endl;
  110.     return 0;
  111. }
  112.  
  113.                 /**
  114.                
  115.  
  116.    
  117.    
  118.  
  119.  
  120.     vector<int> vectorName = arrayName;
  121.  
  122.  
  123.     return vectorName;
  124.  
  125.  
  126. }
  127. ***/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement