Docsity

Fortran 90 Bubble Sort Algorithm: ASCEND and DESCEND Subroutines - Prof. Charles Pruett, Assignments of Mathematics

Toggle sidebar
bg1
Math 248 Computers and Numerical Algorithms–Pruett
LABORATORY ASSIGNMENT
A Bubble-Sorting Subroutine
Background: Recall that, in addition to intrinsic functions, Fortran 90 allows
FUNCTION subprograms and SUBROUTINES, which have somewhat different
purposes. FUNCTIONs return a single value and are accessed simply by using the
name of the function (just like the intrinsic functions). SUBROUTINEs, on the
other hand, usually perform more involved tasks, may return several results, and
are accessed by a CALL statement. A good example of an operation that requires
a simple subroutine in Fortran 90 is sorting. Given a vector of numerical values in
some random order, return the values in sorted (ascending or descending) order.
C In class, we demonstrated a “bubble” sort algorithm to arrange a group of
students by height. In your group (or teamed with another group), write an
algorithm in pseudocode that performs a bubble sort into ascending order.
C Write and compile a Fortran 90 MODULE that contains SUBROUTINE
ASCEND SORT, which performs an ascending-order bubble sort. The ar-
guments to the subroutine should be a vector xthat contains a list of real
numbers, and n, an integer that specifies the size of the vector. On return,
the vector xwill contain the values in sorted order.
B Write a main program that CALLs your subroutine to sort the list following
list: [1.2,0.9,3.7,9.9,8.2,3.3,2.0,0.5].
A Add another SUBROUTINE to your module which performs a descending-
order sort. Call it DESCEND SORT. Hint: cut, paste, and modify.

Partial preview of the text

Download Fortran 90 Bubble Sort Algorithm: ASCEND and DESCEND Subroutines - Prof. Charles Pruett and more Assignments Mathematics in PDF only on Docsity!

Math 248 Computers and Numerical Algorithms–Pruett

LABORATORY ASSIGNMENT

A Bubble-Sorting Subroutine

Background: Recall that, in addition to intrinsic functions, Fortran 90 allows FUNCTION subprograms and SUBROUTINES, which have somewhat different purposes. FUNCTIONs return a single value and are accessed simply by using the name of the function (just like the intrinsic functions). SUBROUTINEs, on the other hand, usually perform more involved tasks, may return several results, and are accessed by a CALL statement. A good example of an operation that requires a simple subroutine in Fortran 90 is sorting. Given a vector of numerical values in some random order, return the values in sorted (ascending or descending) order.

C In class, we demonstrated a “bubble” sort algorithm to arrange a group of students by height. In your group (or teamed with another group), write an algorithm in pseudocode that performs a bubble sort into ascending order.

C Write and compile a Fortran 90 MODULE that contains SUBROUTINE ASCEND SORT, which performs an ascending-order bubble sort. The ar- guments to the subroutine should be a vector x that contains a list of real numbers, and n, an integer that specifies the size of the vector. On return, the vector x will contain the values in sorted order.

B Write a main program that CALLs your subroutine to sort the list following list: [1.2,0.9,3.7,9.9,8.2,3.3,2.0,0.5].

A Add another SUBROUTINE to your module which performs a descending- order sort. Call it DESCEND SORT. Hint: cut, paste, and modify.