Sorting C++
Ini adalah contoh program Sorting pada C++
Dan Dijalankan oleh Software Dev-C++
#include <iostream> #define n 10 using namespace std; int main(){ int A[n]; int I, K, X; for(I=0; I<=9; I++) { cin >> A[I]; } cout<<"\n Sebelum di Sort = "; for(I=0; I<=9; I++) { cout<< A[I]<<" "; } //Sorting for(K=0; K <= n-2; K++) { for(I=0; I<= n-2 - K; I++) {if(A[I] > A[I+1]) { X =A[I]; A[I]= A[I+1]; A[I+1] = X; } } } cout<<"\n\n Sesudah di Sort = "; for(I=0; I<=9; I++) {cout<<A[I]<< " "; } return 0; }
jjk
BalasHapus