Skip to content

kohei-noda-qcrg/heap_sort_fortran_module_test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

heap_sort_fortran_module_test

これはなに

Fortran90による1次元配列(integer,real)のヒープソート実装
ヒープソートは計算量がデータ数Nに対してO(NlogN)であることが保証されている
またインプットの配列の中でデータを入れ替え操作するので、入れ替え操作用のダミー変数及びループインデックス以外の追加のメモリをallocateしないためメモリを圧迫しづらい
ただしWikipediaにもある通り安定ソートではないが、1次元配列のみのサポートなので問題は発生しえない

使い方

FortranのModule機能を用いて実装しているので、外部から

   use module_heapsort
   !! lst is a one-dimentional list (integer or real(8)) that you want to sort.
   call heapSort(lst)

とするだけで昇順ソートされた配列がlstに格納される

How to build

main.f90は使用例になっているので、実際のコードで使いたいときはswap.f90とheap_sort.f90のみをビルドすればよい
Module機能を用いているのでコンパイル順を先にしてswap.mod,heap_sort.modを作りつつビルドするか、先に.modを作ってからビルドすればよい
main.f90でmodule_heapsortがuseされている場合のビルド方法は以下の通り

  gfortran swap.f90 heap_sort.f90 main.f90 -o a.out

About

1次元配列(integer,real)のヒープソート実装とmoduleとinterfaceの使い方のテスト

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published