Fandom

Scratchpad

PLE:Unidad5Ejercicio19

219,281pages on
this wiki
Add New Page
Discuss this page0 Share
/*
Programa:       Unidad5Ejercicio19.cpp
Descripción:    Ordena mediante el método de la baraja (inserción directa).
*/
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <ctime>
using namespace std;

void ordena(int array[]);

const int TAM = 2000;

void main ()
{
        clock_t ini, fin;
        int num[TAM], i, n, pos;

        srand(time(NULL));
        // Generamos valores aleatorios
        for(i= 0; i < TAM; i++)
        {
                num[i] = rand() % 100;
        }

        // Mostramos el array desordenado
        for(i= 0; i < TAM; i++)
        {
                cout << num[i] << '\t';
        }

        ini = clock();
        // Ordena el array
        ordena(num);
        fin = clock();

        // Mostramos el array ordenado
        cout << endl << "Array ordenado" << endl;
        for(i= 0; i < TAM; i++)
        {
                cout << num[i] << '\t';
        }

        cout << "\nTiempo transcurrido \n" << (fin-ini)/(double) CLOCKS_PER_SEC << endl;
        cout << "Fin = " << fin << endl;
        cout << "Ini = " << ini << endl;
        cout << "C_P_S = " << CLOCKS_PER_SEC << endl;

        system("pause");
}

void ordena(int array[])
{
        int i,j, aux;
        for (i=1; i <= TAM-1; i++)
        {
	        aux = array[i];
        	j = i-1;
	        while (array[j] > aux && j >= 0)
        	{
	        	array[j+1] = array[j];
		        j = j-1;
        	}
	        array[j+1]= aux;
        }
}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random wikia