Fandom

Scratchpad

PLE:Unidad5Ejercicio17

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

Also on Fandom

Random wikia