Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PhB
//g++ 7.4.0 ///////////////////////////////////////////////////////////////////////////// //PhB:example of vector as class attribute and use of priority queue //this code is created by Rezaul Hoque on August 17,2022; //contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https://rezaulhoque.wordpress.com,https://hoquestake.blogspot.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; ////////////////////////////////////////////////////////////////////////////// #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; class PhB{ vector<std::string> star; vector<int> rent; public: PhB(vector<std::string> s,vector<int> r); vector<std::string> getS() const; vector<int> getR() const; }; class ComS{ public: bool operator()(const PhB & h1,const PhB& h2) { return h1.getS()<h2.getS(); } }; class ComR{ public: bool operator()(const PhB & h1,const PhB& h2) { return h1.getR()<h2.getR(); } }; PhB::PhB(vector<std::string> s,vector<int> r) { this->star=s; this->rent=r; } vector<std::string> PhB::getS() const { return this->star; } vector<int> PhB::getR() const { return this->rent; } int main() { vector<std::string> c1,c2,c3,c4; c1.push_back("FnF"); c1.push_back("FnF"); c2.push_back("Personal"); c2.push_back("Personal"); c3.push_back("Former Colleagues"); c3.push_back("Former Colleagues"); c4.push_back("Neighbor"); c4.push_back("Neighbor"); vector<int> r1,r2,r3,r4; r1.push_back(900); r1.push_back(321); r2.push_back(345); r2.push_back(444); r3.push_back(222); r3.push_back(333); r4.push_back(111); r4.push_back(150); PhB a(c1,r1); PhB b(c2,r2); PhB c(c3,r3); PhB d(c4,r4); std::cout<<"Category Contact :\n"; priority_queue<PhB, vector<PhB>,ComR> QR; QR.push(a); QR.push(b); QR.push(c); QR.push(d); while (!QR.empty()){ PhB h=QR.top(); QR.pop(); for(int k=0;k<2;k++){ std::cout<<h.getS()[k]<<" "<<h.getR()[k]<<"\n"; } std::cout<<"\n"; } return 0; }
run
|
edit
|
history
|
help
0
q
Anagram finder
Dar
fibonacci
always_late
Perfect Square Solution
odws
Handling new types without using RTTI
Dar
runtime template mode processor