Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ListCPP
//g++ 7.4.0 //List CPP: use of some list methods and functions //this code is created by Rezaul Hoque on October 13,2021;contact: jewelmrh@yahoo.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 <fstream> #include <iomanip> #include <cmath> #include <list> bool smallDec(double x,double y)//get rid of higher decimals { return ( int(x) == int(y));} bool rem( const double& x){ return (x <10.00); } int main() { std::cout.width(35); std::cout.fill('~'); std::cout<<"\n"; std::cout.width(35); std::cout.fill('~'); std::cout<<"\n"; std::list<double> x,y; std::list<char> a,b; a.push_back('L'); a.push_back('i'); a.push_back('s'); a.push_back('t'); a.push_back(' '); a.push_back('i'); a.push_back('n'); a.push_back(' '); a.push_back('a'); a.push_back('c'); a.push_back('t'); a.push_back('i'); a.push_back('o'); a.push_back('n'); a.push_back(':'); a.push_back('\n'); a.push_back('O'); a.push_back('c'); a.push_back('t'); a.push_back('o'); a.push_back('b'); a.push_back('e'); a.push_back('r'); a.push_back(' '); a.push_back('1'); a.push_back('3'); a.push_back(','); x.push_back(2); x.push_back(0); y.push_back(2); y.push_back(1); //use of merge x.merge(y); for(std::list<char>::iterator it=a.begin(); it != a.end(); it++) std::cout<<" "<<*it; for(std::list<double>::iterator it=x.begin(); it != x.end(); it++) std::cout<<" "<<*it; std::cout<<"\n"; double m[]={10.40,10.25,10.30, 8.51,8.55,9.00,9.15,9.30,9.40,10.55,10.21}; std::list<double> mylist (m,m+11); //use of sort() mylist.sort(); std::cout << "The list contains(after sort):\n"; for (std::list<double>::iterator it=mylist.begin(); it!=mylist.end(); ++it) std::cout <<" "<< *it; std::cout <<"\n"; //use of remove_if() mylist.remove_if(rem); std::cout << "The list contains (after removing values lesser than 10.00):\n"; for (std::list<double>::iterator it=mylist.begin(); it!=mylist.end(); ++it) std::cout <<" "<< *it; std::cout <<"\n"; b.push_front(':'); b.push_front('e'); b.push_front('m'); b.push_front('i'); b.push_front('T'); //use of unique() mylist.unique(smallDec); for (std::list<char>::iterator it=b.begin(); it!=b.end(); ++it) std::cout <<" " << *it; for (std::list<double>::iterator it=mylist.begin(); it!=mylist.end(); ++it) std::cout <<" "<< *it; std::cout <<" \n"; std::cout.width(35); std::cout.fill('~'); std::cout<<"\n"; std::cout.width(35); std::cout.fill('~'); std::cout<<"\n"; return 0; }
run
|
edit
|
history
|
help
0
iuadhfaoiufs
Próba
Dijkstra
weird cast in qt moc files
test
Tower of hanoi
PointClassOpLoad
lab17feb22x4B.cpp
template inhertinace
Discounting