🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: es.comp.os.linux.programacion
4 messages
4 total messages Started by Manuel Tue, 01 Nov 2005 15:05
Algoritmo para buscar numeros repetidos en un array?
#1567
Author: Manuel
Date: Tue, 01 Nov 2005 15:05
6 lines
1198 bytes
Hola.

Alguien sabe de algun algoritmo en C, java, etc que me diga si hay numeros 
que estan repetidos en un array?

Sds. 
Re: Algoritmo para buscar numeros repetidos en un array?
#1568
Author: Oscar Garcia
Date: Tue, 01 Nov 2005 17:19
22 lines
1703 bytes
El Tue, 1 Nov 2005 16:05:56 +0100, "Manuel" <no@no.com> escribi�:
>Alguien sabe de algun algoritmo en C, java, etc que me diga si hay numeros 
>que estan repetidos en un array?

for (t=0; t<NUM_ELEMENTOS; t++) {
  for (i=t+1; i<NUM_ELEMENTOS; i++) {
    if (array[t] == array[i]) {
      printf("Hay dos elementos iguales en %d y %d\n",
        i, t);
  }
}

Esta es una forma teniendo en cuenta que los elementos del array no
est�n ordenados (si no se podr�a usar otros algoritmos de b�squeda m�s
optimizados).

Un saludo.

-- 
�scar Javier Garc�a Baudet
LinaresDigital
http://redstar.linaresdigital.com/
Re: Algoritmo para buscar numeros repetidos en un array?
#1569
Author: gamo
Date: Tue, 01 Nov 2005 19:47
36 lines
1899 bytes
  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

--8323328-1551187800-1130874474=:7143
Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

On Tue, 1 Nov 2005, Manuel wrote:

> Hola.
>
> Alguien sabe de algun algoritmo en C, java, etc que me diga si hay numero=
s
> que estan repetidos en un array?
>
> Sds.
>
En Perl ser=EDa algo as=ED como

for $i (@array){
 =09@elem =3D grep ($i, @array);
 =09if (@elem > 1){
 =09=09print "$i repetido\n";
 =09}
}=20
# UNTESTED

Saludos,

--=20
http://www.telecable.es/personales/gamo/
S=F3lo hay 10 tipos de personas, las que saben binario y las que no
GED/GB d+ s+:+ a C++ U+++ P+++ L++ E---- W++ N++ o K+ w O+ M- V
PS++ PE++ Y PGP+ t 5-- X+ R-- tv-- b++ DI++ D+ G- e+++ h+ r-- z
perl -e 'print 111_111_111**2,"\n";'
--8323328-1551187800-1130874474=:7143--
Re: Algoritmo para buscar numeros repetidos en un array?
#1570
Author: Manuel
Date: Tue, 01 Nov 2005 22:25
1 lines
1130 bytes
muchas gracias. 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads