图片排序

来源:互联网 发布:人工智能如何实现 编辑:程序博客网 时间:2024/06/05 05:31

简单的冒泡排序

抽时间写下其他排序方法的

view plaincopy to clipboardprint?
  1. #include<iostream>  
  2. #include<string>  
  3. #include<sstream>  
  4. using namespace std;  
  5. void main(){  
  6.     string str;  
  7.     getline(cin, str);  
  8.     int N = str.size();  
  9.     char temp;   
  10.     for (int i = 0; i < N - 1; i++){  
  11.         for (int j = 0; j < N - 1 - i; j++){  
  12.             if (str[j]>str[j + 1]){  
  13.                 temp = str[j];  
  14.                 str[j] = str[j + 1];  
  15.                 str[j + 1] = temp;  
  16.             }  
  17.         }  
  18.     }  
  19.     cout << str;  
  20.     //system("pause");  
  21.     return;  
  22.   
  23. }  

view plaincopy to clipboardprint?
  1. #include<iostream>  
  2. #include<string>  
  3. #include<algorithm>  
  4.   
  5. using namespace std;  
  6.   
  7. int main()  
  8. {  
  9.     string s;  
  10.     cin>>s;  
  11.     sort(s.begin(),s.end());  
  12.     cout<<s<<endl;  
  13.   
  14.     return 0 ;  
  15. }  

  1. n = strlen(str);  
  2.     sort( str, str + n ); 



0 0
原创粉丝点击