/
Inicio :: Foros

 F.A.Q.F.A.Q.                  Conéctese para revisar sus mensajesConéctese para revisar sus mensajes   

ayuda para generar un arreglo con un millon de numeros

 
      Índice del Foro elrincondelc.com -> Algoritmos
Ver tema anterior :: Ver siguiente tema  
AutorMensaje
david22r



Registrado: 22 Feb 2014
Mensajes: 1
Ubicación: Honduras

MensajePublicado: 22/02/2014 9:03 pm
Título: ayuda para generar un arreglo con un millon de numeros

hola a todos, si me pueden ayudar tengo este programa que ordena un arreglo, n puede ser 10, 100, 1000, 10000, 100000, 1000000, cuando n es 10, 100, 1000, y hasta 10,000 el programa funciona bien y hace lo suyo, pero cuando doy el valor de n 100,000, el random solo me genera hasta un poco mas de 27,000 numero, cabe decir que es un arreglo donde no se repitan los numeros! gracias de antemano

Código:

#include <time.h>
#include <stdio.h>
#include <dos.h>
#include<cstdlib>
#include<ctime>
#include <iostream>
using namespace std;

int getMilisegundos(clock_t c){
    int tiempo=0;
    tiempo = (int)((c/(double)CLOCKS_PER_SEC)*1000) ;
   return tiempo;
}

bool checkrep(int n, int num[], int cant){
    for(int i=0; i<cant; i++)
        if(n == num[i])
            return true;
    return false;
}

int main(){
   int cant;
   cout << "Ingrese N: "; // n puede ser 10, 100, 1000, 10000, 100000, 1000000
   cin >> cant;
      
   int ax = 0;
   int n, num [cant];
   int arreglo[cant];
   srand(time(NULL));
            
    for(int i=0; i<cant; i++)
    {
        do
            n = 1 + rand() % cant;
        while(checkrep(n, num, cant));
        num[i] = n;
    }
    cout << endl;
   
    for (int  y = 0; y < cant; y++)
      arreglo[y] = num[y];
      
    int t1 = 0;
   int t2  = 0;
   int tiempo = 0;       
    
   t1= clock();
          
    for (int  i = 0; i < cant - 1; i++)
      for (int j = i + 1; j < cant; j++){
         if(arreglo[i] > arreglo[j]){
            ax = arreglo[i];
            arreglo[i] = arreglo[j];
            arreglo[j] = ax;
         }
      }   
 
    t2=clock();
 
    //cout << endl << "Arreglo ordenado:" << endl;
   for (int i = 0; i < cant; i++)
      cout << i + 1 << " numero: " << arreglo[i] << endl;
      
    tiempo=getMilisegundos(t2-t1);
    
    //printf("\n Tiempo  de ejecucion = [ %d ] ", tiempo);
    cout << endl << "Tiempo de ejecucion: " << tiempo;
   //cout << endl << "Inicio: " << t1;
    //cout << endl << "Fin: " << t2 << endl; 
    
   
    return 0;
}
Question
Volver arriba
      Índice del Foro elrincondelc.com -> Algoritmos
Página 1 de 1Todas las horas están en GMT - 8 Horas

 
No puede crear mensajes
No puede responder temas
No puede editar sus mensajes
No puede borrar sus mensajes
No puede votar en encuestas

(c) ElRincondelC.com

Un proyecto de UrlanHeat.com