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

Shell sort #37

Open
make-github-pseudonymous-again opened this issue Jun 25, 2015 · 1 comment
Open

Shell sort #37

make-github-pseudonymous-again opened this issue Jun 25, 2015 · 1 comment
Assignees

Comments

@make-github-pseudonymous-again
Copy link
Owner

https://en.wikipedia.org/wiki/Shellsort

@make-github-pseudonymous-again
Copy link
Owner Author

Example in PHP

function shellSort(&$a) {
    $n = count($a);
    $d = floor($n / 2);
    while ($d > 0) {
        for ($i = 0; $i < ($n - $d); $i++) {
            $j = $i;
            while ($j >= 0 && $a[$j] > $a[$j + $d]) {
                list($a[$j], $a[$j + $d]) = array($a[$j + $d], $a[$j]);
                $j--;
            }
        }
        $d = floor($d / 2);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant