Wednesday, September 22, 2010

contoh program buble sort c++

#include
#include

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;
}

void bubble_sort()
{
 for(int i=1;i<=n;i++)
 {
  for(int j=n; j>=i; j--)
  {
    if(data[j] < data[j-1]) tukar(j,j-1);
  }
 }
}
void main()
{
 cout<<"===PROGRAM BUBBLE SORT==="<

 //Input Data
 cout<<"Masukkan Jumlah Data : ";
 cin>>n;
 for(int i=1;i<=n;i++)
 {
  cout<<"Masukkan data ke "<<<" : ";
  cin>>data[i];
  //data2[i]=data[i];
 }

 bubble_sort();

 cout<<"\n\n";
 //tampilkan data
 cout<<"Data Setelah di Sort : ";
 for(i=1; i<=n; i++)
 {
  cout<<" "<
 }
 cout<<"\n\nSorting Selesai";
 getch();

5 comments:

Anonymous said...

Dah dicoba di rumah, tapi kok da warning "multiple variable i" terus yach...Padahal q copy paste doank dari program yg dah da di atas...

ijun said...

hm,,???? tapi bisa di eksekusi gak???
ntar aku cek lagi dirumah ya
oh ya,,salam kenal ya

email aja aku,,,and maaf telat dibalas

ijun said...

oh,,itu mungkin prosesor nya??
kan gak ada ya......

one stop said...

kok g jalan

ijun said...

it masalah di prosesornya mas,,,ade yang kurang coba aja
tambah #include dan #include

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Laundry Detergent Coupons