c++的优先队列的比较函数与Java的比较函数
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c++的优先队列的比较函数与Java的比较函数,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1845字,纯文字阅读大概需要3分钟。
内容图文
![c++的优先队列的比较函数与Java的比较函数](/upload/InfoBanner/zyjiaocheng/702/7cbd3886063240f5896a3168f0a77355.jpg)
package com.file; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.Arrays; class Solution{ private FileInputStream fin; private FileOutputStream fout; private byte data[]; public boolean openFile() throws IOException { fin=new FileInputStream("F:\\tdm-gcc.zip"); fout=new FileOutputStream("F:\\1.zip"); data=new byte[1024]; while(fin.read(data)!=-1) { fout.write(data); data=new byte[1024]; } fin.close(); fout.close(); return true; } } class student implements Comparable<student>{ private String name; private int age; public student(String name, int age) { super(); this.name = name; this.age = age; } @Override public int compareTo(student o) { if(this.age < o.age) return 1; if(this.age > o.age) return -1; return 0; } @Override public String toString() { return "name: "+this.name+","+"age: "+this.age; } } class SortStudent{ public boolean Sort() { student stu=new student("***",14); student stu1=new student("(((",16); student stu2=new student(")))",12); student[]arr= {stu,stu1,stu2}; Arrays.sort(arr); System.out.println(Arrays.toString(arr)); return true; } } public class Main { public static void main(String[] args) throws IOException { SortStudent ss=new SortStudent(); ss.Sort(); } } #include <iostream> #include <vector> #include <algorithm> #include <string> #include <queue> #include <functional> using namespace std; class student{ private: string name; int age; public: bool operator<(const student& obj)const{ return this->age > obj.age; } student(string name, int age){ this->name = name; this->age = age; } string GetName(){ return this->name; } }; int main(){ student s1("****",12); student s2("(((", 15); student s3(")))", 14); priority_queue<student>pq; pq.push(s1); pq.push(s2); pq.push(s3); cout << pq.top().GetName() << endl; pq.pop(); cout << pq.top().GetName() << endl; pq.pop(); cout << pq.top().GetName() << endl; pq.pop(); cin.get(); }
内容总结
以上是互联网集市为您收集整理的c++的优先队列的比较函数与Java的比较函数全部内容,希望文章能够帮你解决c++的优先队列的比较函数与Java的比较函数所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。