Kamis, 01 Maret 2012

Shorting

#include <cstdlib>
#include <iostream>

using namespace std;
void baca_data(int A[], int n){
     int i;
     for(i=0;i<n;i++){
                      cout<<"Data ke- " <<i+1 <<" : "; cin>>A[i];
                      }
     }
    
     void cetak_data(const int A[],int n){
          int i;
    
          for(i=0;i<n;i++)
          cout<<A[i] <<" " <<endl;
          }
         
     void tukar(int *a,int *b){
          int temp;
          temp = *a;
          *a = *b;
          *b = temp;
          }
         
     void buble(int x[], int n){
          int i,j;
          for(i=0;i<n-1;i++)
          for(j=i+1;j<n;j++){
          if(x[i] > x[j]) tukar(&x[i],&x[j]);}
          }
    
int main(int argc, char *argv[])
{
    int data[10],n;
    cout<<"Banyak data  : "; cin>>n;
    baca_data(data,n);
    cout<<endl <<"DATA AWAL  " <<endl;
    cout<<"***************************************" <<endl;
    cetak_data(data,n);
    buble(data,n);
    cout<<endl <<endl <<"SETELAH DIURUTKAN "<<endl;
    cout<<"***************************************" <<endl;
    cetak_data(data,n);
   
    cout<<endl<<endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}



fahmi,s blogPosted By Fahmi's BLog

Semoga informasi yang Fahmi's sampaikan sangat bermanfaat bagi Kita semua contact me

Thank You

0 komentar:

Posting Komentar