Trace Presortmode Algorithm Array 11 14 12 13 12 11 12 14 13 12 Modevalue Modefrequency R Q37127662

Trace the PresortMode algorithm with the array A = [11, 14, 12,13, 12, 11, 12, 14, 13, 12]. What is the modevalue, modefrequency,and runvalue after three iterations of the outer while loop?


Solution


#include<iostream>
#include<algorithm>
using namespace std;
int main(){
//input array   
int A[]={11, 14, 12, 13, 12, 11, 12, 14, 13, 12};

int i = 0, runLength,runvalue,modefrequency=0,modevalue;
// size of the array
int size= sizeof(A)/sizeof(A[0]);
cout << “The size of the array is : “<< size<<endl;

// sort the array
sort(A,A+size);
cout << “Array after applying sorting :”<< endl;
for (int i=0;i<size;i++){
   cout <<A[i]<< ” “;
}
cout << endl;
int j=1;
// iterate till the size-1
while(i<size){
   runLength = 1;
   runvalue = A[i];
   // count

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.