• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Aug 14th, 2010 195 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. //Programa para ordenacion de datos
2.
3. #include <iostream>
4. #include <fstream>
5. #include <cstdlib>
6.
7. void insercion(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.         insercion(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 insercion(int n, int *a) {
61.
62.    int i, b, index;
63.
64.    for (i=1; i < n; i++) {
65.
66.       index = a[i];
67.
68.       b = i-1;
69.
70.       while (b >= 0 && a[b] > index) {
71.
72.          a[b + 1] = a[b];
73.
74.          b--;
75.
76.       }
77.
78.       a[b+1] = index;
79.
80.    }
81.
82. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top