document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // program to implement bubble sorting algorithm
  2. #include <iostream>
  3. #include<vector>
  4. #include<sstream>
  5.  
  6. using namespace std;
  7. vector<int> bubbleSort(vector<int>);
  8. int main()
  9. {
  10.  
  11.     int n;
  12.     string str;
  13.     vector<int> ints;
  14.  
  15.     cout<<"Enter the array to be sorted : ";
  16.     cin>>str;
  17.  
  18.     for (string::iterator it = str.begin(); it != str.end(); ++it) {
  19.         if (*it == \',\') {
  20.             *it = \' \';
  21.         }
  22.         else continue;
  23.     }
  24.  
  25.     stringstream ss(str);
  26.  
  27.     while(ss >> n){
  28.         ints.push_back(n);
  29.     }
  30.  
  31.     ints = bubbleSort(ints);
  32.     cout<<"\\nThe Array after sorting is : ";
  33.     for(int i=0; i<ints.size(); i++){
  34.         cout<<ints[i]<<" ";
  35.     }
  36. }
  37.  
  38. vector<int> bubbleSort(vector<int> numbers){
  39.     int temp;
  40.     for(int i=0; i<numbers.size()-1; i++){
  41.         for(int j=0; j< numbers.size()-1; j++){
  42.             if(numbers[j] > numbers[j+1]){
  43.                 temp = numbers[j];
  44.                 numbers[j] = numbers[j+1];
  45.                 numbers[j+1] = temp;
  46.             }
  47.         }
  48.     }
  49.     return numbers;
  50. }
');