先按年齡排序,要是年齡相等的話,就按名字的順序排序

2021-08-31 13:03:35 字數 570 閱讀 5931

//先按年齡排序,要是年齡相等的話,就按名字的順序排序;

public class user implements comparable

public void setname(string name)

public int getage()

public void setage(int age)

public int compareto(user o) else

}//測試類

public class test }}

&&&&&&&&&&&&&&&&&&&&&& 上面和下面實現的功能是一樣的注意觀察不同點

pojo

public class user implements comparator

public void setname(string name)

public int getage()

public void setage(int age)

public int compare(user o1, user o2) else}}

測試類public class test }}

年齡排序9

題目描述 對乙個公司的所有員工 可能上萬 的年齡排序,只允許使用常量大小的輔助空間。解題思路 採用長度100的整數陣列作為輔助空間,對0 99歲出現的次數進行計數。某個年齡出現多少次,就在原陣列依次 下標 按順序重新賦值排列。測試用例 測試用例 int main sortages函式實現 void ...

所有員工年齡排序

何海濤 劍指offer 名企面試官精講典型程式設計題 九度oj 題目描述 公司現在要對所有員工的年齡進行排序,因為公司員工的人數非常多,所以要求排序演算法的效率要非常高,你能寫出這樣的程式嗎?輸入 輸入可能包含多個測試樣例,對於每個測試案例,輸入的第一行為乙個整數n 1 n 1000000 代表公司...

員工年齡排序演算法

對公司幾萬員工年齡排序 include vector include iostream using namespace std void arrayprint int a,int n void sortages0 int ages,int length int count 0 for size t ...