fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. template<typename T>
  5. void bubble(vector<T>& arr){
  6. int n = arr.size();
  7. for(int i=0; i<n-1; i++){
  8. for(int j=0; j<n-i-1; j++){
  9. if(arr[j]> arr[j+1]){
  10. T temp = arr[j];
  11. arr[j] = arr[j+1];
  12. arr[j+1] = temp;
  13. }
  14. }
  15. }
  16. }
  17. template<typename T>
  18. void print(vector<T>& arr){
  19. for(int i=0; i< arr.size(); i++){
  20. cout << arr[i] << " ";
  21. }
  22. cout << endl;
  23. }
  24. int main() {
  25. int n;
  26. cin>>n;
  27. vector<int> arr(n);
  28. for(int i=0; i<n; i++){
  29. cin >> arr[i];
  30. }
  31. bubble(arr);
  32. print(arr);
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0.01s 5320KB
stdin
6
059 6 4 585 2 54
stdout
2 4 6 54 59 585