elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Which code block uses bubble sort?
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Which code block uses bubble sort?  (Leído 2,312 veces)
pixielott

Desconectado Desconectado

Mensajes: 2


Ver Perfil WWW
Which code block uses bubble sort?
« en: 15 Septiembre 2020, 16:56 pm »

Hey,
May I know which one is bubble sort from here:

1)
Código:
for(int i=0;i<n-1;i++)
  for(int j=n-1; j>i;j--)
    if(a[j] < a[j-1])
        swap(a[j], a[j-1]);

2)
Código:
for(int i=0; i<n-1; i++)
  for(int j=i+1; j<n; j++)
    if(a[j] < a[i])
        swap(a[j],a[i]);
3)
Código:
int temp, i, j = 0;
    boolean swaped = true;

    while (swaped) {
        swaped = false;
        j++;
        for(i = 0; i < arr.length - j; i++){
            if(arr[i] > arr[i+1]){
                temp = arr[i];
                arr[i] = arr[i+1];
                arr[i+1] = temp;
                swaped = true;
            }
        }
    }

IMO, the first is bubble sort, not sure of the second and third.









En línea

MCKSys Argentina
Moderador Global
***
Desconectado Desconectado

Mensajes: 5.465


Diviértete crackeando, que para eso estamos!


Ver Perfil
Re: Which code block uses bubble sort?
« Respuesta #1 en: 15 Septiembre 2020, 17:30 pm »

Hi!

The 2nd one is bubble sort.

Cheers!

PS: In case you didn't notice, this is a spanish talking forum. I'm sure you could find any in hindi language.


En línea

MCKSys Argentina

"Si piensas que algo está bien sólo porque todo el mundo lo cree, no estás pensando."

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines