/* file: selection_sort.cpp @author Didik Kurniawan */ #include <iostream> using namespace std; int data[]={12,34,21,23,12,32,56,21,42,21,21,41,11,53,22}; int panjang=sizeof(data)/sizeof(data[0]); void swap(int &a, int &b) { int temp; temp=a; a=b; b=temp; } int max(int i){ int besar = data[0],idx_besar=0; for (int j=0;j<panjang-i;j++) { if (data[j]>besar) { besar=data[j]; idx_besar=j; } } return idx_besar; } int main(){ for (int i=0;i<panjang; i++){ cout<<data[i]<<", "; } cout<<endl<<"Sort with Selection" <<endl; for (int k=0;k<panjang; k++){ int besar=max(k); swap(data[besar],data[panjang-k-1]); } for (int i=0;i<panjang; i++){ cout<<data[i]<<", "; } return 0; }