View Single Post
Join Date: Dec 2008
Posts: 18
Reputation: da penguin is an unknown quantity at this point 
Solved Threads: 5
da penguin's Avatar
da penguin da penguin is offline Offline
Newbie Poster

Re: sorting characters in a string... help!!!!

 
0
  #5
Jan 1st, 2009
Introducing bubble sort

  1. #include <iostream>
  2. #include <string>
  3.  
  4. int main()
  5. {
  6. std::string str;
  7. std::cin >> str;
  8.  
  9. char tmp;
  10.  
  11. int i,j;
  12. for(i=0;i<str.size()-1;++i) {
  13. for(j = i+1;j<str.size();++j) {
  14. if(str[i] < str[j])
  15. {
  16. tmp = str[i];
  17. str[i] = str[j];
  18. str[j] = tmp;
  19. }
  20. }
  21. }
  22.  
  23. std::cout << str;
  24.  
  25. return 0;
  26. }
This works.
No, ma'am, we are musicians.
Reply With Quote