CE 311K Lab6 - Lab. Arrays and Sorting Margaret Thompson...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lab. Arrays and Sorting Margaret Thompson Section No. 14885 02/19/08 1. SCREEN PRINT OUT 2. CODE ! CE311K Introduction to Computer Methods ! Lab 6 ! Array and Sorting ! Programmed by Margaret Thompson ! 2/19/2008 Program EarthquakeSort Implicit None ! Declaration of variables Character*60 Name(219), Temp_name, tempN Real Lat(219), Long(219), Date(219),tempD,tempLt,tempLo Integer Num, i, j, n, count Integer swapped Open (unit=6, file='output.txt', status='unknown') Open (unit=5, file='quakes.txt', status='old') Read (5,*) Num ! Initialization of the arrays Do i=1,Num Read (5,*) Date(i),Name(i), Lat(i), Long(i) Enddo n=Num write (6,150) swapped=1 count=0 DO while (swapped.eq.1) swapped=0 Do j=1,n-1 if (Date(j).lt.Date(j+1)) then tempD = Date(j) tempN = Name(j) tempLt = Lat(j) tempLo = Long(j) Date(j) = Date(j+1) Name(j) = Name(j+1) Lat(j) = Lat(j+1) Long(j) = Long(j+1) Date(j+1) = tempD Name(j+1) = tempN Lat(j+1) = tempLt Long(j+1) = tempLo swapped=1 count= count+1 Endif EndDo EndDo write(6,50) WRITE(6,100) (Date(i), Name(i), Lat(i), Long(i), i = 1, Num) write(6,350) count write (6,200) swapped=1 count=0 DO while (swapped.eq.1) swapped=0 Do j=1,n-1 if (Name(j).gt.Name(j+1)) then tempD = Date(j) tempN = Name(j) tempLt = Lat(j) tempLo = Long(j) Date(j) = Date(j+1) Name(j) = Name(j+1) Lat(j) = Lat(j+1) Long(j) = Long(j+1) Date(j+1) = tempD Name(j+1) = tempN Lat(j+1) = tempLt Long(j+1) = tempLo swapped=1 count= count+1 Endif EndDo EndDo Write(6,50) WRITE(6,100) (Date(i), Name(i), Lat(i), Long(i), i = 1, Num) write(6,350) count i=1;j=1 write (6,250) do while (i<=n-1) if (j<1) then i=i+1 j=i else if (Lat(j+1)>Lat(j)) then tempD = Date(j) tempN = Name(j) tempLt = Lat(j) tempLo = Long(j) Date(j) = Date(j+1) Name(j) = Name(j+1) Lat(j) = Lat(j+1) Long(j) = Long(j+1) Date(j+1) = tempD Name(j+1) = tempN Lat(j+1) = tempLt Long(j+1) = tempLo count= count+1 Endif j=j-1 endif enddo write(6,50) WRITE(6,100) (Date(i), Name(i), Lat(i), Long(i), i = 1, Num) write(6,350) count i=1;j=1 write (6,300) do while (i<=n-1) if (j<1) then i=i+1 j=i else if (Long(j+1)<Long(j)) then tempD = Date(j) tempN = Name(j) tempLt = Lat(j) tempLo = Long(j) Date(j) = Date(j+1) Name(j) = Name(j+1) Lat(j) = Lat(j+1) Long(j) = Long(j+1) Date(j+1) = tempD Name(j+1) = tempN Lat(j+1) = tempLt Long(j+1) = tempLo count= count+1 Endif j=j-1 endif enddo write(6,50) WRITE(6,100) (Date(i), Name(i), Lat(i), Long(i), i = 1, Num) write(6,350) count ! Format statements 50 Format (1x, 'Date', 10x, 'Name', 44x, 'Latitude', 3x, 'Longitude') 100 Format (f7.2, 1x, A50, 3x, f8.3, 5x, f8.3) 150 Format (//, 'Bubble Algorithm 1',//) 200 Format (//, 'Bubble Algorithm 2',//) 250 Format (//, 'Insertion Algorithm 1',//) 300 Format (//, 'Insertion Algorithm 2',//) 350 Format (/,'Swaps made:', I10) End 3. OUTPUT FILE Bubble Algorithm 1 Date Name Latitude Longitude 2007.10 CALIFORNIA:_SAN_JOSE_ 37.434 -121.774 2007.08 ALASKA:_ALEUTIAN_ISLANDS_ 51.307 -179.971 2007.08 UTAH:_HUNTINGTON_ 39.465 -111.237 2007.08 UTAH_ 39.464 39....
View Full Document

Page1 / 20

CE 311K Lab6 - Lab. Arrays and Sorting Margaret Thompson...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online