Skip to content

Commit 423a8b4

Browse files
committed
added an example for sorting array of bitset_large
1 parent 6154e2b commit 423a8b4

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

example/sorting/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
ADD_EXAMPLE(ord_sort)
22
ADD_EXAMPLE(sort)
3-
ADD_EXAMPLE(radix_sort)
3+
ADD_EXAMPLE(radix_sort)
4+
ADD_EXAMPLE(sort_bitsetl)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
program example_sort_bitsetl
2+
use stdlib_sorting, only: sort
3+
use stdlib_bitsets
4+
implicit none
5+
type(bitset_large), allocatable :: array(:)
6+
7+
array = [bitset_l("0101"), & ! 5
8+
bitset_l("0100"), & ! 4
9+
bitset_l("0011"), & ! 3
10+
bitset_l("0001"), & ! 1
11+
bitset_l("1010"), & ! 10
12+
bitset_l("0100"), & ! 4
13+
bitset_l("1001")] ! 9
14+
15+
call sort(array)
16+
17+
block
18+
integer(int32) :: i
19+
do i = 1, size(array)
20+
print *, to_string(array(i))
21+
! 0001
22+
! 0011
23+
! 0100
24+
! 0100
25+
! 0101
26+
! 1001
27+
! 1010
28+
end do
29+
end block
30+
31+
deallocate(array)
32+
contains
33+
function bitset_l(str) result(new_bitsetl)
34+
character(*), intent(in) :: str
35+
type(bitset_large) :: new_bitsetl
36+
37+
call new_bitsetl%from_string(str)
38+
end function bitset_l
39+
40+
function to_string(bitset) result(str)
41+
type(bitset_large), intent(in) :: bitset
42+
character(:), allocatable :: str
43+
44+
call bitset%to_string(str)
45+
end function to_string
46+
end program example_sort_bitsetl

0 commit comments

Comments
 (0)