C++学习
serendipity_小白
这个作者很懒,什么都没留下…
展开
-
位运算——不利于第三个变量交换两个整数
位运算 (学习记录) void myswap(int &a, int&b){ if (a!=b){ a ^= b; b ^= a; a ^= b; } } 假设:a=5;b=10 a=0000 0000 0000 0101 b=0000 0000 0000 1010 a = a ^ a =0000 0000 0000 0000 b = b ^ b =0000 0000 0000 0000 b = b ^ a = b ^ a ^ b = b ^ b ^ a = 0000 00原创 2022-03-20 17:32:58 · 85 阅读 · 0 评论 -
C++选择排序——学习笔记
按从大到小排列 #include <iostream> #include <vector> using namespace std; void Myprintnums(vector<int>& nums){ for (auto i:nums){ cout << i << " "; } cout << endl; } void Myselectsort(vector<int>& nums){ i原创 2022-02-13 02:13:50 · 204 阅读 · 0 评论 -
C++冒泡排序——学习笔记
按从大到小排列 #include <iostream> #include <vector> using namespace std; void Myprintnums(vector<int>& nums){ for(auto i:nums){ cout << i <<" "; } cout << endl; } void Mybubblesort(vector<int>& nums){ int原创 2022-02-12 16:07:09 · 377 阅读 · 0 评论