Cod sursa(job #2237228)

Utilizator TeodorLuchianovTeo Luchianov TeodorLuchianov Data 1 septembrie 2018 10:33:27
Problema Sortare prin comparare Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <iostream>
#include <fstream>

using namespace std;


ifstream in("algsort.in");
ofstream out("algsort.out");


int const nmax = 500000;
int n;
int v[1 + nmax];

void bubblesort() {
  for(int i = 1; i <= n; i++) {
  //in interiorul acestui for, NICIODATA nu se modifica sau redefineste i
    int lim = n - (i - 1);
    for(int j = 1; j < lim; j++) {
      if(v[j] > v[j + 1]){
        int k = v[j];
        v[j] = v[j + 1];
        v[j + 1] = k;
      }
    }
  }
}

int main() {
  in >> n;
  for(int i = 1; i <= n; i++) {
    in >> v[i];
  }
  bubblesort();
  for(int i = 1; i <= n; i++) {
    out << v[i] << " ";
  }
  return 0;
}