Fandom

Scratchpad

PLE:Unidad5Ejercicio18

215,994pages on
this wiki
Add New Page
Discuss this page0 Share

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.

/*
Programa:       Unidad5Ejercicio18.cpp
Descripción:    Ordena mediante el método de la selecció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,k,aux;
        for (i = 0; i < TAM-1; i++)
        {
	        k = i;
        	aux = array[i];
	        for (j = i+1; j <= TAM-1; j++)
        	{
	        	if (array[j] < aux)
		        {
			        k = j;
        			aux = array[j];
	        	}
        	}
	        array[k] = array[i];
        	array[i] = aux;
        }
}

Also on Fandom

Random wikia