MaTLaB DeRS-5 - MF-102 Bilgisayar Programlama Bahar 2008(5....

Info iconThis preview shows pages 1–6. 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: MF-102 Bilgisayar Programlama Bahar 2008(5. Hafta)(Yrd. Do. Dr. Deniz Dal)K MATLAB DEKENNN DEERLERNN YER DETRMES (SWAPPNG)geciciDegisken=A;A=B;B=geciciDegisken;AB!!! GEC BR DEKENE HTYA VAR !!!Sralama yani Sorting nemli Bir Problem1 - Kkten Bye Sralama (Artan) (Ascending Sort)2 - Bykten Ke Sralama (Azalan) (Descending Sort) A=[3 1 2]Artan SralA=[1 2 3] >>sort(A) veyasort(A,ascend)Azalan SralA=[3 2 1] >>sort(A,descend)(MATLABde tanmli bu sortfonksiyonunu kullanmayacaz bizler. Kendi sortprogramlarmz yazacaz.) Selection Sort(Sralama Algoritmas)Bu algoritma birinci elemandan balayarak sonelemana kadar, sralanmam DZYpara parasralar. nce dizideki en kk eleman bulunur vedizinin ilk eleman ile yer deitirilir (swap). Sonrakiaamada dizinin sralanmam olan paras iindeki enkk eleman bulunur ve ikinci elemanla yer deitirilir.Bu ilemi N defa tekrarladmzda N elemanl bir diziyisralam oluruz."Selection Sort"ile Kkten Bye Sralamaclc;clear;A=round(1+49*rand(1,20)) %Siralanmamis Diziyi Yazdirtic%Siralamaya Baslamadan Once Kronometreyi Calistirfori=1:(length(A)-1)minimum=i;forj=(i+1):length(A) ifA(j)<A(minimum)minimum=j;endend%yer degistir (swap)geciciDegisken=A(i);A(i)=A(minimum);A(minimum)=geciciDegisken;endtoc%Siralama Bittikten Sonra Kronometreyi DurdurA %Siralanmis Diziyi YazdirBubble Sort...
View Full Document

This note was uploaded on 04/23/2010 for the course ENGINEERİ CS 111 taught by Professor - during the Spring '10 term at Bilkent University.

Page1 / 16

MaTLaB DeRS-5 - MF-102 Bilgisayar Programlama Bahar 2008(5....

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

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