例如:我的列表是{1,1,2,2}
然后我会有m [0] = 4 q [0] = 1
然后m [1] = 3,q [1] = 2.
所以模式是q [0] = 1;
不幸的是,到目前为止我没有成功.希望有人可以提供帮助.
float mode(int x[],int n){ //copy array and sort it int y[n],temp,k = 0,counter = 0,m[n],q[n]; for(int i = 0; i < n; i++) y[i] = x[i]; for(int pass = 0; pass < n - 1; pass++) for(int pos = 0; pos < n; pos++) if(y[pass] > y[pos]) { temp = y[pass]; y[pass] = y[pos]; y[pos] = temp; } for(int i = 0; i < n;){ for(int j = 0; j < n; j++){ while(y[i] == y[j]) { counter++; i++; } } m[k] = counter; q[k] = y[i]; i--; //i should be 1 less since it is referring to an array subscript k++; counter = 0; }}解决方法 即使你已经有了一些好的答案,我决定发布另一个.我不确定它真的增加了很多新的东西,但我不确定它也不是.如果不出意外,我很确定它使用的标准标题比任何其他答案都要多. 总结
以上是内存溢出为你收集整理的c – 计算模式的算法全部内容,希望文章能够帮你解决c – 计算模式的算法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)