Fandom

Scratchpad

PLE:Unidad5Ejercicio02

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:         Unidad5jercicio02cpp
Fecha:            15/03/2007
Descripción:      Arrasy dinámico.
*/

#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

void ordena(int * p, int n);
void visualiza(int *p, int n);
void generaValores(int *p, int n);

void main()
{
        int *p, n;

        cout << "Introduzca el numero de elementos del array: ";
        cin >> n;

        p = new int[n];

        generaValores(p, n);
        ordena(p,n);
        visualiza(p,n);

        cin.ignore();
        cin.get();
}

void visualiza(int *p, int n)
{
        cout << "Elementos del array " << endl;
        for( int i=0; i < n; i++)
                cout << *(p+i) << endl;
}

void generaValores(int *p, int n)
{
        for( int i=0; i < n; i++)
                *(p+i) = rand();
}


void ordena(int * p, int n)
{
        int i,j, aux;
        for(i=0; i < n-1; i++)
        {
	        for(j = 1 ;j < n; j++)
        	{
	        	if(*(p+j-1) > *(p+j))
		        {
        			aux = *(p+j);
	        		*(p+j) = *(p+j-1);
		        	*(p+j-1) = aux;
        		}
	        }
        }
}

Also on Fandom

Random wikia