Cod sursa(job #1423818)

Utilizator abel1090Abel Putovits abel1090 Data 22 aprilie 2015 19:59:45
Problema Sortare prin comparare Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.57 kb
///SORTING
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>

using namespace std;

void insertionSort(vector<int>& A) {
   int j;
   for(int i=1; i<A.size(); ++i) {
      j = i;
      while(j && A[j-1] > A[j]) {
         swap(A[j-1], A[j]);
         --j;
      }
   }
}

int main() {
   ifstream inStr("algsort.in");
   ofstream outStr("algsort.out");

   int N;
   inStr >> N;

   vector<int> A(N);

   for(int i=0; i<N; ++i)
      inStr >> A[i];

   insertionSort(A);

   for(auto curr : A)
      outStr << curr << ' ';
   outStr << '\n';

   return 0;
}