The below program written in FORTRAN is a bubble sort for a single dimensional array
rewrite the program below for a multidemensional array following the provided template.
the data.txt file looks something like this where the first line is the size of the array
4 3
1 1 1
2 2 2
3 3 3
4 4 4
follow this template
program rowBubbleSortExample
implicit none
!Parameter Declarations
!Variable Declarations
!Ask user for file to open
!Try to read first line for row and column sizes
!Try to create the array with the provided dimensions
!Read file into array
!Ask user for column to sort by
!Bubble Sort (See provided example)
!Open output file
!Check to see that output file opened successfully
!Write array into output file with row and columns in header
end program
THIS PROGRAM IS WRITTEN FOR A SINGLE DIMENSIONAL ARRAY REWRITE IT INTO A MULTIDIMENSIONAL ARRAY
program bubbleSort
implicit none
integer, parameter :: arraySize = 10
integer, dimension(arraySize) :: array = (/5,-3,4,6,2,19,1000,23,-44,-1000/)
integer :: i, j
integer :: temporary
logical :: swapMade
write(*,*) "Unsorted List: ", (array(i), i=1,arraySize,1)
!With each iteration through the array,
!the highest indexed values are
!guaranteed to be sorted.
do j = 0, arraySize-2, 1
swapMade = .false.
do i = 2,arraySize - j,1
if(array(i)
!Swap the values
temporary = array(i)
array(i)=array(i-1)
array(i-1)=temporary
swapMade = .true.
end if
end do
if(swapMade .eqv. .false.) then
exit !End the sort early if no swaps were made
end if
end do
write(*,*) "Sorted List: ", (array(i), i=1,arraySize,1)
end program