I need to build an algorithm that allows you to adjust an array

0

I must do it in the following way:

If you find a blank box, you must move the elements to the beginning to occupy that space, the idea is that the available spaces are at the end of the arrangement.

This is what I have, since I do not understand how I can do the blank boxes and move them to the beginning, and look in videos and nothing.

Proceso  ajustar_arreglo
Dimension arreglo_ajustado[10];

Definir i, arreglo_ajustado como entero;
Definir var_aux como entero;

i<-0;

para i<-0 hasta 9 Hacer
    arreglo_ajustado[i]<-azar(20);
FinPara

para i<-0 hasta 7 Hacer
    si arreglo_ajustado[i]>arreglo_ajustado[i+1] Entonces
        var_aux<-arreglo_ajustado[i];
        arreglo_ajustado[i]<-arreglo_ajustado[i+1];
        arreglo_ajustado[i+1]<-var_aux;
    FinSi
FinPara

Escribir '';
Escribir 'mostrar ordenado';
Para i<-0 hasta 9 hacer
    Escribir arreglo_ajustado[i];
FinPara
FinProceso
    
asked by Sebastian Ortiz 12.07.2017 в 02:11
source

1 answer

0

Bubbling is an algorithm that orders a list of one movement at a time. Therefore, you will go through the list as many times as necessary until the list is fully sorted.

For this, a flag is used to clarify if any movement was made, and the list is run from end to end moving the necessary elements.

In pseudocodigo, the algorithm comes in the following way:

flag = true
Mientras flag = true
    flag = false
    Desde iniciolista hasta finlista-1
        si posicionactual < posicionactual+1
            cambiar las posiciones
            flag = true
        fin si
    fin desde
fin mientras

Notice that this orders from the highest to the smallest list ... and runs it as many times as necessary.

Now, with the theme of spaces, it depends on language. In general, all languages treat spaces as characters smaller than numbers and letters, therefore such an arrangement should leave spaces in the background. however, if this is not the case, one should send the spaces to the bottom before doing this, and count them, and take the end of the list, the last space that is not white.

    
answered by 13.07.2017 в 16:33