Tugas Algoritma Dan Pemrograman.docx

  • Uploaded by: Alfrida Putri Puspita
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Tugas Algoritma Dan Pemrograman.docx as PDF for free.

More details

  • Words: 1,304
  • Pages: 17
TUGAS ALGORITMA DAN PEMROGRAMAN BUBBLE SORT (ASCENDING)

Alfrida Putri Puspitasari 171810101042

Jurusan Matematika Fakultas Matematika dan Ilmu Pengetahuan Alam Universitas Jember 2018

Data = [43 42 38 36 35 33 32 31 30 28 27] n = 11 for i = 1 : 10 

i=1 pos=1

for j = 2:11 

j=2

if data (j) > data (pos) if data (2) > data (1) if 42 > 43

(salah )

end 

j=3

if 38 > 43

(salah)

end 

j=4

if 36 > 43

(salah)

end 

j=5

if 35 > 43

(salah)

end j=7 if 27 < 33 temp = 27 data (7) = 33

(benar)

data (6) = 27 end j=6 if 27 < 35

(benar)

temp = 27 data (6) = 35 data (5) = 27 end j=5 if 27 < 36

(benar)

temp = 27 data (5) = 36 data (4) = 27 end j=4 if 27 < 38

(benar)

temp = 27 data (4) = 38 data (3) = 27 end j=3 if 27 < 42 temp = 27 data (3) = 42

(benar)

data (2) = 27 end j=2 if 27 < 43

(benar)

temp = 27 data (2) = 43 data (1) = 27 end end hasil proses ke 1 = [27 43 42 38 36 35 33 32 31 30 28]



i=2

for j = 11 : -1: 3 j = 11 if data (11) < data (10) if 28 < 30

(benar)

temp =28 data(11)=30 data(10)=28 end j = 10 if 28 < 31 temp = 28 data (10) = 30 data (9) = 28

(benar)

end j=9 if 28 < 32

(benar)

temp = 28 data (9) = 32 data (8) = 28 end

j=8 if 28 < 33

(benar)

temp = 28 data (8) = 33 data (7) = 28 end j=7 if 28 < 35

(benar)

temp = 28 data (7) = 35 data (6) = 28 end j=6 if 28 < 36 temp = 28

(benar)

data (6) = 36 data (5) = 28 end j=5 if 28 < 38

(benar)

temp = 28 data (5) = 38 data (4) = 28 end j=4 if 28 <42

(benar)

temp = 28 data (4) = 42 data (3) = 28 end j=3 if 28 < 43

(benar)

temp = 28 data (3) = 42 data (2) = 28 end end hasil proses ke 2 = [27 28 43 42 38 36 35 33 32 31 30]



i=3

for j = 11 : -1: 4 j = 11 if data (11) < data (10) if 30 < 31

(benar)

temp =30 data(11)=31 data(10)=30 end j = 10 if 30 < 32

(benar)

temp = 30 data (10) = 32 data (9) = 30 end j=9 if 30 < 33

(benar)

temp = 30 data (9) = 33 data (8) = 30 end

j=8 if 30 < 35 temp = 30

(benar)

data (8) = 35 data (7) = 30 end j=7 if 30 < 36

(benar)

temp = 30 data (7) = 36 data (6) = 30 end j=6 if 30 < 38

(benar)

temp = 30 data (6) = 38 data (5) = 30 end j=5 if 30 < 42

(benar)

temp = 30 data (5) = 42 data (4) = 30 end j=4 if 30 <43 temp = 30

(benar)

data (4) = 43 data (3) = 30 end end hasil proses ke 3 = [27 28 30 43 42 38 36 35 33 32 31] 

i=4

for j = 11 : -1: 5 j = 11 if data (11) < data (10) if 31 < 32

(benar)

temp =31 data(11)=32 data(10)=31 end j = 10 if 31 < 33

(benar)

temp = 31 data (10) = 33 data (9) = 31 end j=9 if 31 < 35 temp = 30 data (9) = 35

(benar)

data (8) = 31 end

j=8 if 31 < 36

(benar)

temp = 31 data (8) = 36 data (7) = 31 end j=7 if 31 < 38

(benar)

temp = 31 data (7) = 38 data (6) = 31 end j=6 if 31 < 42

(benar)

temp = 31 data (6) = 42 data (5) = 31 end j=5 if 31 < 43

(benar)

temp = 31 data (5) = 43 data (4) = 31 end end hasil proses ke 4 = [27 28 30 31 43 42 38 36 35 33 32] 

i=5

for j = 11 : -1: 6 j = 11 if data (11) < data (10) if 32 < 33

(benar)

temp =32 data(11)=33 data(10)=32 end j = 10 if 32 < 35

(benar)

temp = 32 data (10) = 35 data (9) = 32 end j=9 if 32 < 36 temp = 32

(benar)

data (9) = 36 data (8) = 32 end j=8 if 32 < 38

(benar)

temp = 32 data (8) = 38 data (7) = 32 end j=7 if 32 < 42

(benar)

temp = 32 data (7) = 42 data (6) = 32 end j=6 if 32 < 43

(benar)

temp = 32 data (6) = 43 data (5) = 32 end end hasil proses ke 5 = [27 28 30 31 32 43 42 38 36 35 33]



i=6

for j = 11 : -1: 7 j = 11 if data (11) < data (10) if 33 < 35

(benar)

temp =33 data(11)=35 data(10)=33 end j = 10 if 33 < 36

(benar)

temp = 33 data (10) = 36 data (9) = 33 end j=9 if 33 < 38

(benar)

temp = 33 data (9) = 38 data (8) = 33 end j=8 if 33 < 42 temp = 33

(benar)

data (8) = 42 data (7) = 33 end j=7 if 33 < 43

(benar)

temp = 33 data (7) = 43 data (6) = 33 end end hasil proses ke 6 = [27 28 30 31 32 33 43 42 38 36 35]



i=7

for j = 11 : -1: 8 j = 11 if data (11) < data (10) if 35 < 36

(benar)

temp =35 data(11)=36 data(10)=35 end j = 10 if 35 < 38 temp = 35

(benar)

data (10) = 38 data (9) = 35 end j=9 if 35 < 42

(benar)

temp = 35 data (9) = 42 data (8) = 35 end j=8 if 35 < 43

(benar)

temp = 35 data (8) = 43 data (7) = 35 end end hasil proses ke 7 = [27 28 30 31 32 33 35 43 42 38 36] 

i=8

for j = 11 : -1: 9 j = 11 if data (11) < data (10) if 36 < 38 temp =36 data(11)=38

(benar)

data(10)=36 end j = 10 if 36 < 42

(benar)

temp = 36 data (10) = 42 data (9) = 36 end j=9 if 36 < 43

(benar)

temp = 36 data (9) = 43 data (8) = 36 end end hasil proses ke 8 = [27 28 30 31 32 33 35 36 43 42 38] 

i=9

for j = 11 : -1: 10 j = 11 if data (11) < data (10) if 38 < 42 (benar) temp =38 data(11)=42 data(10)=38

end j = 10 if 38 < 43

(benar)

temp = 38 data (10) = 43 data (9) = 38 end end hasil proses ke 9 = [27 28 30 31 32 33 35 36 38 43 42] 

i = 10

for j = 11 : -1: 11 j = 11 if data (11) < data (10) if 42 < 43 (benar) temp =42 data(11)=43 data(10)=42 end end hasil proses ke 10 = [27 28 30 31 32 33 35 36 38 42 43] Bubble Short Ascending [27 28 30 31 32 33 35 36 38 42 43]

Related Documents


More Documents from ""

4. Gravimetri.ppt
June 2020 1
Bab 9.docx
June 2020 1
Bab I.docx
November 2019 52