Sha256: 17cc8e87b1dad6bc951424b077e1a9c625a3ccb56d3009b58d8fd7ae7466f82f

Contents?: true

Size: 713 Bytes

Versions: 4

Compression:

Stored size: 713 Bytes

Contents

#include <iostream>
#include <vector>
#include <stdlib.h>

using namespace std;

vector<int> bubble_sort(vector<int> numbers) {
  int n = numbers.size();
  for(int i = 0; i < n; i++) {
    for(int j = i; j < n; j++) {
      if (numbers[i] > numbers[j]) {
        int temp = numbers[i];
        numbers[i] = numbers[j];
        numbers[j] = temp;
      }
    }
  }
  return numbers;
}

int main() {
  vector<int> numbers;
  int v;
  
  // Reading the input
  while (cin >> v)
    numbers.push_back(v);
  
  numbers = bubble_sort(numbers);
  
  // Printing the output
  vector<int>::iterator it;
  for (it = numbers.begin(); it < numbers.end()-1; it++)
    cout << (*it) << " ";
  cout << (*it);
    
  return 0;
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jeka-0.2.3 test/bubble_sort/cpp/bubble_sort.cpp
jeka-0.2.2 test/bubble_sort/cpp/bubble_sort.cpp
jeka-0.2.1 test/bubble_sort/cpp/bubble_sort.cpp
jeka-0.2.0 test/bubble_sort/cpp/bubble_sort.cpp