http://www.geeksforgeeks.org/sort-elements-by-frequency-set-2/

 #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
#include <map>
using namespace std; void printarray(int arr[], int n) {
map<int, int> S;
for (int i = ; i < n; i++) {
if (S.find(arr[i]) == S.end()) S[arr[i]] = ;
else S[arr[i]]++;
}
map<int, vector<int> > T;
for (map<int, int>::iterator it = S.begin(); it != S.end(); it++) {
T[it->second].push_back(it->first);
}
for (map<int, vector<int> >::iterator it = T.end(); it != T.begin();) {
it--;
vector<int> tmp = it->second;
for (int j = ; j < tmp.size(); j++) {
for (int k = ; k < it->first; k++) cout << tmp[j] << " ";
}
}
} int main() {
int arr[] = {, , , , , , , , , , };
printarray(arr, );
return ;
}

Data Structure Array: Sort elements by frequency的更多相关文章

  1. Data Structure Array: Given an array of of size n and a number k, find all elements that appear more than n/k times

    http://www.geeksforgeeks.org/given-an-array-of-of-size-n-finds-all-the-elements-that-appear-more-tha ...

  2. Data Structure Array: Maximum sum such that no two elements are adjacent

    http://www.geeksforgeeks.org/maximum-sum-such-that-no-two-elements-are-adjacent/ #include <iostre ...

  3. Data Structure Array: Find the Missing Number

    http://www.geeksforgeeks.org/find-the-missing-number/ 1. use sum formula, O(n), O(1) 2. use XOR, O(n ...

  4. Data Structure Array: Move all zeroes to end of array

    http://www.geeksforgeeks.org/move-zeroes-end-array/ #include <iostream> #include <vector> ...

  5. Data Structure Array: Find if there is a subarray with 0 sum

    http://www.geeksforgeeks.org/find-if-there-is-a-subarray-with-0-sum/ #include <iostream> #incl ...

  6. Data Structure Array: Maximum circular subarray sum

    http://www.geeksforgeeks.org/maximum-contiguous-circular-sum/ #include <iostream> #include < ...

  7. Data Structure Array: Largest subarray with equal number of 0s and 1s

    http://www.geeksforgeeks.org/largest-subarray-with-equal-number-of-0s-and-1s/ #include <iostream& ...

  8. Data Structure Array: Find the two numbers with odd occurrences in an unsorted array

    http://www.geeksforgeeks.org/find-the-two-numbers-with-odd-occurences-in-an-unsorted-array/ #include ...

  9. Data Structure Array: Longest Monotonically Increasing Subsequence Size

    http://www.geeksforgeeks.org/longest-monotonically-increasing-subsequence-size-n-log-n/ #include < ...

随机推荐

  1. logstash5安装并实现mariadb数据写入到elasticsearch

    java环境这里默认安装了 ,一般源码安装,这里就不说了 一.安装logstash 安装logstash可以用yum安装,也可以用源码安装: yum安装: 1.导入GPG: rpm --import ...

  2. leetcode第一刷_Binary Tree Zigzag Level Order Traversal

    以出现的频率来看.树的层序遍历一定是考察的重点,除非工作人员想找题水数量. zigzag,还是有几道题的,层序的这个非常easy,假设是奇数层.reverse下面就可以.无他.我写的时候预计还不知道这 ...

  3. Debug与Trace工具类的应用

    在写Console程序的时候,能够使用Console.WriteLine()来时时的输出程序的执行状态和各种參数此刻的信息.可是假设是Windows Form程序,我们要怎样实时的观測程序的执行状况呢 ...

  4. Angular 资料大集合

    https://angular.cn/   Angular 的中文网 http://www.apjs.net/#dir1    Angular 的中文网 http://www.ngnice.com/  ...

  5. 使用javac,手动编译一个java文件的方法

    参考<Tomcat与Java Web开发技术详解>中的命令: javac -classpath c:\tomcat\lib\servlet-api.jar                  ...

  6. httpd在嵌入式中应用

    在启动脚本合适位置添加: httpd -h /usr/app/www/ 即开始httpd服务,并定位到/usr/app/www/ 注:busybox已支持httpd命令,所以直接用即可. busybo ...

  7. 将普通用户添加至sudoers列表

    编辑/etc/sudoers文件,在尾部添加如下内容: myusername ALL=(ALL) ALL myusername ALL=(ALL) NOPASSWD: ALL 其中需要将红色部分替换成 ...

  8. python第三方库地址

    python第三方库的地址: requests: http://docs.python-requests.org/zh_CN/latest/user/quickstart.html beautifus ...

  9. jQuery Easy UI Draggable(拖动)组件

    上文已经提到过了 jQuery EasyUI插件引用一般我们经常使用的有两种方式(排除easyload载入方式),所以本篇要总结的Draggable组件相同有两种方式载入: (1).使用class载入 ...

  10. java拾遗2----XML解析(二) SAX解析

    XML解析之SAX解析: SAX解析器:SAXParser类同DOM一样也在javax.xml.parsers包下,此类的实例可以从 SAXParserFactory.newSAXParser() 方 ...