Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Programa para ordenacion de datos
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- void insercion(int n, int *a);
- using namespace std;
- int main() {
- system ("clear");
- ifstream label1 ("datos.in");
- int i, j, n = -1;
- int a[20];
- while (!label1.eof()){
- n += 1;
- label1 >> a[n];
- }
- cout << "El archivo tiene " << n << " valores\n";
- label1.close();
- cout << "Serie desordenada de valores\n";
- for (i=0; i < n; i++){
- cout << a[i] << " ";
- }
- cout << "\n";
- insercion(n,a); //funcion ordenar
- cout << "Serie ordenada de valores\n";
- for (i=0; i < n; i++){
- cout << a[i] << " ";
- }
- cout << "\n";
- return 0;
- }
- void insercion(int n, int *a) {
- int i, b, index;
- for (i=1; i < n; i++) {
- index = a[i];
- b = i-1;
- while (b >= 0 && a[b] > index) {
- a[b + 1] = a[b];
- b--;
- }
- a[b+1] = index;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement