gpt4 book ai didi

perl - Perl 高级排序如何通过使用排序函数中的 $a 和 $b 值对值进行排序

转载 作者:行者123 更新时间:2023-12-02 09:25:54 24 4
gpt4 key购买 nike

@array=sort{$a <=> $b} @input;
@input = qw \ 3 4 5 1 6 3 9 \;

这是 Perl 如何在内部对值进行排序的。

那么perl高级排序中值的排序方式以及使用哪种排序方法对值进行排序以及如何排序?

最佳答案

perldoc sort :

Perl 5.6 and earlier used a quicksort algorithm to implement sort. That algorithm was not stable and could go quadratic. (A stable sort preserves the input order of elements that compare equal. Although quicksort's run time is O(NlogN) when averaged over all arrays of length N, the time can be O(N**2), quadratic behavior, for some inputs.) In 5.7, the quicksort implementation was replaced with a stable mergesort algorithm whose worst-case behavior is O(NlogN).

关于perl - Perl 高级排序如何通过使用排序函数中的 $a 和 $b 值对值进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38098723/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com