#include { countNum(a,middle+1,finish); while(!inf.eof())
//return count; } int main() { int s[1000]; ifstream inf("1.txt"); int i=0;
扩展资料
#include
template
voidinsertion_sort(biIterbegin,biIterend)
{
typedeftypenamestd::iterator_traits
biIterbond=begin;
std::advance(bond,1);
for(;bond!=end;std::advance(bond,1)){
value_typekey=*bond;
biIterins=bond;
biIterpre=ins;
std::advance(pre,-1);
while(ins!=begin&&*pre>key){
*ins=*pre;
std::advance(ins,-1);
std::advance(pre,-1);
}
*ins=key;
}
}
参考资料:百度百科 排序
public static void main(String[] args) {
int array[]={5, 10, 10, 5, 2, 5, 3, 5, 10, 5, 2, 5, 5, 10, 1, 5, 1};
Arrays.sort(array);// 给数组排序
int count=0;
int tmp=array[0];
Map map=new HashMap();
for(int i=0; i < array.length; i++) {
if(tmp != array[i]) {
tmp=array[i];
count=1;
} else {
count++;
}
map.put(array[i], count);
}
map=sortByValue(map);
Set
for (Iterator it = key.iterator(); it.hasNext();) {
Integer s = (Integer) it.next();
System.out.println(s+"出现了"+map.get(s));
}
}
public static Map sortByValue(Map map) {
List list=new LinkedList(map.entrySet());
Collections.sort(list, new Comparator() {
// 将链表按照值得从小到大进行排序
public int compare(Object o1, Object o2) {
return ((Comparable)((Map.Entry)(o2)).getValue()).compareTo(((Map.Entry)(o1)).getValue());
}
});
Map result=new LinkedHashMap();
for(Iterator it=list.iterator(); it.hasNext();) {
Map.Entry entry=(Map.Entry)it.next();
result.put(entry.getKey(), entry.getValue());
}
return result;
}
/***求出一个数组中出现次数最多的数,如果有多个数出现次数相同,一同列出 */import java.util.TreeMap;import java.util.Iterator;import java.util.Map;import java.util.Set;import java.util.Arrays;class ArrayLookup{public void getMaxCount(int[] iArr){int i = 0; //临时变量 int j = 0; //临时变量int count = 1; //记录相同数字出现次数int temp = 0; //记录数组中相同元素的值int max = 0; //记录出现次数最多的数 //数组排序Arrays.sort(iArr);TreeMap
for(i=0;i
}
用增强FOR循环