tugas Insertion Sort c++

8,698 views

Published on

Published in: Education, Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
8,698
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
247
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

tugas Insertion Sort c++

  1. 1. Kelompok 5<br />NamaKelompok : <br />PutuSumaye ( 100010537)<br />Sandy Yon Wibowo (100010527) <br />GdeAdiWidiantara(100010530) <br />WiryaKusuma (100010528)<br />Prianata Putra S (100010554)<br />
  2. 2. Insertion Sort<br /><ul><li>Pengertian
  3. 3. Contoh Program Insertion sort</li></li></ul><li>Insertion Sort<br />• Metodepenyisipan (Insertion sort)<br />bertujuan untuk menjadikan bagian sisi kiri<br />array terurutkansampaidenganseluruh<br />array berhasildiurutkan.<br />• Metodeinimengurutkanbilangan-bilangan<br />yang telahdibaca; danberikutnyasecara<br />berulangakanmenyisipkanbilanganbilangan<br />dalam array yang belumterbaca<br />kesisikiri array yang telahterurut.<br />
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11.
  12. 12.
  13. 13.
  14. 14. Contoh Program Insertion sort<br />
  15. 15. Berikutadalah syntax dari insertion sort dalam C++ :#include <iostream.h>#include <conio.h>int data[10],data2[10];int n;void tukar(int a, int b){ int t; t = data[b]; data[b] = data[a]; data[a] = t;}<br />
  16. 16. void insertion_sort(){ inttemp,i,j; for(i=1;i<=n;i++) {  temp = data[i];  j = i -1;  while(data[j]>temp && j>=0)  {   data[j+1] = data[j];   j--;  } data[j+1] = temp; }}void main(){ cout<<"===PROGRAM INSERTION SORT==="<<endl;<br />
  17. 17. //Input Data cout<<"MasukkanJumlah Data : "; cin>>n; for(inti=1;i<=n;i++) {  cout<<"Masukkan data ke "<<i<<" : ";  cin>>data[i];  data2[i]=data[i]; } insertion_sort(); cout<<"nn"; //tampilkan data cout<<"Data Setelahdi Sort : "; for(inti=1; i<=n; i++) {  cout<<" "<<data[i]; } cout<<"nnSortingSelesai"; getch();}<br />
  18. 18. TerimaKasih<br />

×