Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
MoveBubble
//g++ 7.4.0 ///////////////////////////////////////////////////////////////////////////// //MoveBubble: use of move semantics in Bubble sort //this code is created by Rezaul Hoque on June 29,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 <string> #include <utility> #include <vector> template<class T> void swap(T& a,T& b) { T temp {std::move(a)}; a=std::move(b); b=std::move(temp); } template<class T> void Bsort(T* a) { int n=5; for(int h=1;h<n;h++) for(int j=0;j<n-h;j++) if (a[j]>a[j+1]) swap(a[j],a[j+1]); } int main() { std::string a[5]={"Hello","Hola","Ni Hao","Salut","Konnichiwa"}; for(int i=0;i<5;i++) std::cout<<" "<<a[i]; Bsort(a); std::cout<<" \n"; for(int i=0;i<5;i++) std::cout<<" "<<a[i]; std::cout<<" \n"; std::vector<std::string> s; for(int i=0;i<5;i++) s.push_back(std::move(a[i])); std::cout<<" \n"; for(int i=0;i<5;i++) std::cout<<" "<<s[i]; std::cout<<"\nAfter std::move a:\n"; for(int i=0;i<5;i++) std::cout<<" "<<a[i]; return 0; }
run
|
edit
|
history
|
help
0
TraiectorieIdeala2
IAR compiler bug test code
Example Iterator Increment
Tower of hanoi
palindrome
ignat2
ExceptionWhat
e-olymp.com---problem1590---Birthday 2
t>0
sdefrgthyjukiujyhtg