Advertisement
Guest User

Untitled

a guest
Aug 14th, 2010
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. //Programa para ordenacion de datos
  2.  
  3. #include <iostream>
  4. #include <fstream>
  5. #include <cstdlib>
  6.  
  7. void ordenar (int n, int *a);
  8.  
  9. using namespace std;
  10.  
  11. int main() {
  12.  
  13.     system ("clear");
  14.  
  15.     ifstream label1 ("datos.in");
  16.  
  17.     int i, j, n = -1;
  18.  
  19.     int a[20];
  20.  
  21.     while (!label1.eof()){
  22.  
  23.         n += 1;
  24.  
  25.         label1 >> a[n];
  26.  
  27.  
  28.     }
  29.  
  30.     cout << "El archivo tiene " << n << " valores\n";
  31.  
  32.     label1.close();
  33.  
  34.     cout << "Serie desordenada de valores\n";
  35.  
  36.     for (i=0; i < n; i++){
  37.  
  38.         cout << a[i] << " ";
  39.  
  40.     }
  41.  
  42.     cout << "\n";
  43.  
  44.     ordenar(n,a); //funcion ordenar
  45.  
  46.     cout << "Serie ordenada de valores\n";
  47.  
  48.     for (i=0; i < n; i++){
  49.  
  50.         cout << a[i] << " ";
  51.  
  52.     }
  53.  
  54.     cout << "\n";
  55.  
  56.     return 0;
  57.  
  58. }
  59.  
  60. void ordenar (int n, int *a){
  61.  
  62.     int i, j, mayor;
  63.  
  64.     for (i=0; i < n-1; i++){
  65.  
  66.         for (j=0; j < n-1; j++){
  67.  
  68.             if(a[j] > a[j+1]){
  69.  
  70.                 mayor = a[j];
  71.            
  72.                 a[j] = a[j+1];
  73.  
  74.                 a[j+1] = mayor;
  75.            
  76.             }
  77.  
  78.         }
  79.  
  80.     }
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement