Skip to content

Added Selection Sort & Minor Changes #5

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

Merged
merged 3 commits into from
Oct 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions sorting/bubblesort.f95
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
program testbubblesort
integer lst(10)
lst = (/ 10, 9, 8, 4, 5, 6, 7, 3, 2, 1 /)
call bubblesort(lst, 0, 10)
call bubblesort(lst, 1, 10)
call show(lst)
end program testbubblesort

Expand All @@ -13,12 +13,12 @@ subroutine bubblesort(lst, a, b)
integer y
integer tmp
do x = a, b-1
do y = a, b-x-1
do y = a, b-x
if (lst(y) .gt. lst(y+1)) then
tmp = lst(y)
lst(y) = lst(y+1)
lst(y+1) = tmp
endif
end if
end do
end do
end
Expand Down
2 changes: 1 addition & 1 deletion sorting/insertionsort.f95
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
program testinsertionsort
integer lst(10)
lst = (/ 10, 9, 8, 4, 5, 6, 7, 3, 2, 1 /)
call insertionsort(lst, 0, 10)
call insertionsort(lst, 1, 10)
call show(lst)
end program testinsertionsort

Expand Down
37 changes: 37 additions & 0 deletions sorting/selectionsort.f95
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
program testselectionsort
integer lst(10)
lst = (/ 10, 9, 8, 4, 5, 6, 7, 3, 2, 1 /)
call selectionsort(lst, 1, 10)
call show(lst)
end program testselectionsort

subroutine selectionsort(lst, a, b)
integer a
integer b
integer lst(10)
integer i
integer j
integer min_id
integer tmp
do i = a, b-1
min_id = i
do j = i+1, b
if (lst(min_id) .gt. lst(j)) then
min_id = j
end if
end do
tmp = lst(i)
lst(i) = lst(min_id)
lst(min_id) = tmp
end do
end

subroutine show(lst)
integer lst(10)
integer x
do x = 1, 10
print 100, lst(x)
end do

100 format (i0)
end