sort升序降序排列
1 #include <bits/stdc++.h> 2 using namespace std; 3 void basicSort(){ 4 vector<int> nums{3,5,2,1,6,9,7}; 5 sort(nums.begin(),nums.end()); 6 cout<<"升序"; 7 for(int n:nums) cout<<n<<" "; 8 cout<<endl; 9 sort(nums.rbegin(),nums.rend()); 10 cout<<"降序"; 11 for(int n:nums) cout<<n<<" "; 12 } 13 int main(int argc, char** argv) { 14 basicSort(); 15 return 0; 16 }

浙公网安备 33010602011771号