Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting #9

Open
szepeviktor opened this issue Apr 25, 2015 · 0 comments
Open

Sorting #9

szepeviktor opened this issue Apr 25, 2015 · 0 comments

Comments

@szepeviktor
Copy link

szepeviktor commented Apr 25, 2015

This is my bubble sort funtion

declare -a VERSION=( ... )
BUBBLE="1"
while [ "$BUBBLE" == 1 ]; do
    BUBBLE="0"
    for I in $(seq 0 "$((${#VERSIONS[@]} - 1))"); do
        # Skip first element
        [ "$I" == 0 ] && continue

        PREVIOUS="$((I - 1))"
        if semverGT "${VERSIONS[$PREVIOUS]}" "${VERSIONS[$I]}"; then
            BUBBLE="1"
            BUFFER="${VERSIONS[$I]}"
            VERSIONS[$I]="${VERSIONS[$PREVIOUS]}"
            VERSIONS[$PREVIOUS]="$BUFFER"
        fi
    done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant