暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Python 排序算法演示

生有可恋 2022-08-08
623

今天推荐一个可视化演示排序算法的 Github 项目,可玩性非常高,从视觉上感受冒泡排序、快速排序、堆排序等排序算法。


项目地址:

  • https://github.com/LucasPilla/Sorting-Algorithms-Visualizer


程序演示:


使用方法,通过 git 下载项目代码,安装依赖,然后运行主程序即可:

    $ git clone https://github.com/LucasPilla/Sorting-Algorithms-Visualizer.git
    Cloning into 'Sorting-Algorithms-Visualizer'...
    remote: Enumerating objects: 939, done.
    remote: Counting objects: 100% (283/283), done.
    remote: Compressing objects: 100% (70/70), done.
    remote: Total 939 (delta 247), reused 215 (delta 213), pack-reused 656
    Receiving objects: 100% (939/939), 42.79 MiB | 1.07 MiB/s, done.
    Resolving deltas: 100% (526/526), done.


    $ cd Sorting-Algorithms-Visualizer


    $ pip3 install -r requirements.txt
    Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
    Collecting pygame
    Downloading https://mirrors.aliyun.com/pypi/packages/33/63/3358b79ac62cc67e4051add2f3da13f15c92050c7acc1b73538b7bf32d95/pygame-2.1.2-cp310-cp310-win_amd64.whl (8.4 MB)
    ---------------------------------------- 8.4/8.4 MB 11.2 MB/s eta 0:00:00
    Installing collected packages: pygame
    Successfully installed pygame-2.1.2


    $ python3 main.py


    使用 python 运行 main.py 时,会弹出一个图形窗口。其中可选的算法类型有:


    里面有很多排序算法都没有听说过,增大延迟可以更清楚地看清排序的过程。在项目代码的 algorithms 目录,有写好的各种排序函数,演示程序调用的就是这些排序函数。



    看动图看能否猜出是哪种排序:


    全文完。


    如果转发本文,文末务必注明:“转自微信公众号:生有可恋”。


    文章转载自生有可恋,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

    评论